Online Java Compiler By
JavaTpoint.com
import java.lang.annotation.Annotation; public class ClassgetAnnotationsExample1 { public static void main(String []args) { ClassgetAnnotationsExample1 clsobj = new ClassgetAnnotationsExample1(); Class cls = clsobj.getClass(); Annotation[] a = cls.getAnnotations(); if(a.length != 0) { for(Annotation val : a) { System.out.println(val.toString()); //print annotation value. } } else { System.out.println("Annotations not set"); } } }
Output