public @interface MyAnnotation {
String value() default "default value";
int count() default 0;
}
@MyAnnotation(value = "Hello", count = 5)
public class MyClass {
// ...
}
public class AnnotationProcessor {
public static void process(Class<?> clazz) {
if (clazz.isAnnotationPresent(MyAnnotation.class)) {
MyAnnotation annotation = clazz.getAnnotation(MyAnnotation.class);
System.out.println("Value: " + annotation.value());
System.out.println("Count: " + annotation.count());
}
}
}
@MyAnnotation(value = "Hello", count = 5)
public void myMethod() {
// ...
}