VOOZH about

URL: https://www.geeksforgeeks.org/java/field-getdeclaredannotations-method-in-java-with-examples/

⇱ Field getDeclaredAnnotations() method in Java With Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Field getDeclaredAnnotations() method in Java With Examples

Last Updated : 24 Apr, 2023

The getDeclaredAnnotations() method of java.lang.reflect.Field is used to return annotations that are directly present on this Field object and ignores inherited annotations. If there are no annotations directly present on this element, the return value is an empty array. The caller can modify the returned array as method sent a copy of the actual object; it will have no effect on the arrays returned to other callers. 

Syntax:

public Annotation[] getDeclaredAnnotations()

Parameters: This method accepts nothing. 

Return: This method returns annotations directly present on this element. 

Below programs illustrate getDeclaredAnnotations() method: 

Program 1: 

Output:
[]

Program 2: 

Comment