Field getAnnotatedType() method in Java With Examples Last Updated : 30 May, 2022 Comments Improve Suggest changes Like Article Like Report The getAnnotatedType() method of java.lang.reflect.Field is used to return an annonatedType object that represents the use of a type to specify the declared type of the field. Every Field of the class is declared by some AnnotatedType.AnnotatedType represents the potentially annotated use of any type including an array type, a parameterized type, a type variable, or a wildcard type currently running in Java Virtual Machine. The returned AnnotatedType instance can be an implementation of AnnotatedType itself or an implementation of one of its sub-interfaces: AnnotatedArrayType, AnnotatedParameterizedType, AnnotatedTypeVariable, AnnotatedWildcardType. Syntax: public AnnotatedType getAnnotatedType() Parameters: This method accepts nothing. Return: This method returns an object representing the declared type of the field represented by this Field. Below programs illustrate getAnnotatedType() method: Program 1: Java // Java program to illustrate // getAnnotatedType() method import java.lang.reflect.AnnotatedType; import java.lang.reflect.Field; import java.util.Arrays; public class GFG { private int number; public static void main(String[] args) throws NoSuchFieldException { // get Field object Field field = GFG.class .getDeclaredField("number"); // apply getAnnotatedType() method AnnotatedType annotatedType = field.getAnnotatedType(); // print the results System.out.println( "Type: " + annotatedType .getType() .getTypeName()); System.out.println( "Annotations: " + Arrays .toString( annotatedType .getAnnotations())); } } Output:Type: int Annotations: [] Program 2: Java // Java Program to illustrate // getAnnotatedType() method import java.lang.annotation.*; import java.lang.reflect.*; import java.util.Arrays; public class GFG { private int @SpecialNumber[] number; public static void main(String[] args) throws NoSuchFieldException { // get Field object Field field = GFG.class .getDeclaredField("number"); // apply getAnnotatedType() method AnnotatedType annotatedType = field.getAnnotatedType(); // print the results System.out.println( "Type: " + annotatedType .getType() .getTypeName()); System.out.println( "Annotations: " + Arrays .toString( annotatedType .getAnnotations())); System.out.println( "Declared Annotations: " + Arrays .toString( annotatedType .getDeclaredAnnotations())); } @Target({ ElementType.TYPE_USE }) @Retention(RetentionPolicy.RUNTIME) private @interface SpecialNumber { } } Output:Type: int[] Annotations: [@GFG$SpecialNumber()] Declared Annotations: [@GFG$SpecialNumber()] References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getAnnotatedType-- Comment More infoAdvertise with us Next Article Field getAnnotatedType() method in Java With Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions java-lang-reflect-package Java-Field Practice Tags : Java Similar Reads Field getAnnotationsByType() method in Java With Examples The getAnnotationsByType() method of java.lang.reflect.Field is used to return annotations that are associated with this field element. This is an important method to get annotation for Field object. If there are no annotations associated with this Field element, the return empty array. The caller c 2 min read Field getAnnotation() method in Java With Examples The getAnnotation() method of java.lang.reflect.Field is used to return returns Field objects for the specified type if such an annotation is present, else null.This is important method to get annotation for Field object. Syntax: public <T extends Annotation> T getAnnotation(Class<T> ann 2 min read Field getType() method in Java with Examples The getType() method of java.lang.reflect.Field used to get the declared type of the field represented by this Field object.This method returns a Class object that identifies the declared type Syntax: public String getType() Parameters: This method accepts nothing. Return value: This method returns 2 min read Field getGenericType() method in Java with Examples The getGenericType() method of java.lang.reflect.Field used to return a Type object representing the declared type of this Field object. The returned type object can be one of the implementations of Type's subinterfaces: GenericArrayType, ParameterizedType, WildcardType, TypeVariable, Class. If the 2 min read Field getName() method in Java with Examples The getName() method of java.lang.reflect.Field used to get the name of the field represented by this Field object. When a class contains a field and we want to get the name of that field then we can use this method to return the name of Field. Syntax: public String getName() Parameters: This method 3 min read Field getInt() method in Java with Examples The getInt() method of java.lang.reflect.Field used to get the value of int which has to be static or instance field type. This method also used to get the value of another primitive type convertible to type int via a widening conversion. When a class contains a static or instance int field and we w 3 min read Field get() method in Java with Examples The get() method of java.lang.reflect.Field used to get the value of the field object. If Field has a primitive type then the value of the field is automatically wrapped in an object. If the field is a static field, the argument of obj is ignored; it may be null Otherwise, the underlying field is an 3 min read Field getModifiers() method in Java with Examples The getModifiers () method of java.lang.reflect.Field used to return the modifiers used for the field object as time of declaration, as an integer. The Modifier class should be used to decode the modifiers. Syntax: public int getModifiers() Parameters: This method accepts nothing. Return: This metho 1 min read Field getDeclaredAnnotations() method in Java With Examples 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 r 2 min read Class getAnnotationsByType() method in Java with Examples The getAnnotationsByType() method of java.lang.Class class is used to get the annotations of the specified annotation type present in this class. The method returns an array of annotations for the specified annotation type. Syntax: public A[] getAnnotationsByType(Class<T> annotationClass) Para 2 min read Like