Online Java Compiler By
JavaTpoint.com
//import statements import java.lang.annotation.Inherited; //import inherited import java.lang.annotation.Retention; //import retention import java.lang.annotation.RetentionPolicy; //import retention policy import java.util.Arrays; public class ClassgetAnnotationsByteExample2 { public static void main(String... args) { Class1 obj = new Class1(); Deprecated[] dep = Class1.class.getAnnotationsByType(Deprecated.class); System.out.println(" " +Arrays.toString(dep)); Annotation1[] ann = Class1.class.getAnnotationsByType(Annotation1.class); System.out.println(" " +Arrays.toString(ann)); } @Deprecated public static class Class1 extends SuperClass1 { Class1() { System.out.println("subClass Constructor Executing..."); } } @Annotation1 public static class SuperClass1 { SuperClass1() { System.out.println("MySuperClass Constructor Executing..."); } } @Retention(RetentionPolicy.RUNTIME) @Inherited private static @interface Annotation1 { } }
Output