@Entity
public class User {
@Id
private int id;
// ...
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Log {
String message();
}
public class LogProcessor {
public static void processAnnotations(Class<?> clazz) {
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Log.class)) {
Log annotation = method.getAnnotation(Log.class);
String message = annotation.message();
System.out.println("Log message: " + message);
}
}
}
}
public class Main {
@Log(message = "Hello, World!")
public static void main(String[] args) {
LogProcessor.processAnnotations(Main.class);
}
}