Online Java Compiler By
JavaTpoint.com
//import statements? import java.lang.annotation.Annotation; //import annotation import java.lang.annotation.Inherited; //import Inherited import java.lang.annotation.Retention; //import retention import java.lang.annotation.RetentionPolicy; //import retention policy public class ClassgetDeclaredAnnotationExample2 { public static void main(String... args) { Annotation ann = Class1.class.getDeclaredAnnotation(Deprecated.class); System.out.println(ann); ann = Class1.class.getDeclaredAnnotation(Annotation1.class); System.out.println(ann); ann = Class.class.getAnnotation(Deprecated.class); System.out.println(ann); ann = Class1.class.getAnnotation(Annotation1.class); System.out.println(ann); } @Deprecated public static class Class1 implements Interface1 { } @Annotation1 public static interface Interface1 { } @Retention(RetentionPolicy.RUNTIME) @Inherited private static @interface Annotation1 { } }
Output