import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Serializable { } @Serializable public class MyClass { // Class implementation goes here } import java.lang.annotation.Annotation; public class AnnotationProcessor { public static void main(String[] args) { MyClass myClass = new MyClass(); Annotation[] annotations = myClass.getClass().getAnnotations(); for (Annotation annotation : annotations) { if (annotation instanceof Serializable) { System.out.println("Class is serializable"); } } } } shell javac -processor AnnotationProcessor MyClass.java


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