Class getDeclaredAnnotations() method in Java with Examples
The getDeclaredAnnotations() method of java.lang.Class class is used to get the declared annotations present in this class. The method returns an array of declared annotations present.
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.
public DeclaredAnnotation getDeclaredAnnotations()
Parameter: This method does not accepts any parameter.
Return Value: This method returns an array of declared annotations present.
Below programs demonstrate the getDeclaredAnnotations() method.
Class represented by myClass: class Test DeclaredAnnotation of myClass: [@java.lang.Deprecated()]
Class represented by myClass: class Test DeclaredAnnotation of myClass: [@DeclaredAnnotation(key=GFG, value=GeeksForGeeks)]