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() { // ... }


上一篇:
下一篇:
切换中文