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.lang.reflect.Method; import java.lang.annotation.Annotation; //import annotation import java.util.Arrays; public class ClassgetDeclaredAnnotationbytypeExample2 { public static void main(String... args) { Deprecated[] dec = subClass1.class.getAnnotationsByType(Deprecated.class); //getannotationbytype System.out.println(Arrays.toString(dec)); //print statement Annotation1[] ann = subClass1.class.getAnnotationsByType(Annotation1.class); //getannotationbytype System.out.println(Arrays.toString(ann)); //print statement String ann1 = subClass1.class.getCanonicalName(); System.out.println(ann1); //print statement } @Deprecated public static class subClass1 extends SuperClass1 { } @Annotation1 public static class SuperClass1 { } @Retention(RetentionPolicy.RUNTIME) @Inherited private static @interface Annotation1 { } }
Output