Class getAnnotations() method in Java with Examples
The getAnnotations() method of java.lang.Class class is used to get the annotations present in this class. The method returns an array of annotations present.
public Annotation getAnnotations()
Parameter: This method does not accepts any parameter.
Return Value: This method returns an array of annotations present.
Below programs demonstrate the getAnnotations() method.
Class represented by myClass: class Test Annotation of myClass: [@java.lang.Deprecated()]
Class represented by myClass: class Test Annotation of myClass: [@Annotation(key=GFG, value=GeeksForGeeks)]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.