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 ClassgetDeclaredAnnotationbytypeExample1 { public static void main(String... args) { Deprecated[] dec = Class1.class.getAnnotationsByType(Deprecated.class); //getannotationbytype System.out.println(Arrays.toString(dec)); //print statement Annotation1[] ann = Class1.class.getAnnotationsByType(Annotation1.class); //getannotationbytype System.out.println(Arrays.toString(ann)); //print statement } @Deprecated public static class Class1 extends SuperClass1 { } @Annotation1 public static class SuperClass1 { } @Retention(RetentionPolicy.RUNTIME) @Inherited private static @interface Annotation1 { } }
Output