VOOZH about

URL: https://www.geeksforgeeks.org/java/class-getannotations-method-in-java-with-examples/

⇱ Class getAnnotations() method in Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Class getAnnotations() method in Java with Examples

Last Updated : 12 Jul, 2025
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. Syntax:
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. Example 1: Output:
Class represented by myClass: class Test
Annotation of myClass: [@java.lang.Deprecated()]
Example 2:
Output:
Class represented by myClass: class Test
Annotation of myClass: [@Annotation(key=GFG, value=GeeksForGeeks)]
Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#getAnnotations--
Comment