Field getGenericType() method in Java with Examples Last Updated : 30 May, 2022 Comments Improve Suggest changes Like Article Like Report 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 Type of Field object is a parameterized type, the returned Type object must accurately reflect the actual type parameters used in the source code and if the type of the underlying field is a type variable or a parameterized type, it is created. Otherwise, it is resolved. Syntax: public Type getGenericType() Parameters: This method accepts nothing. Return: This method returns a Type object that represents the declared type for the field represented by this Field object. Exception: This method returns the following Exceptions: GenericSignatureFormatError: if the generic field signature does not conform to the format specified in The Java™ Virtual Machine Specification.TypeNotPresentException: if the generic type signature of the underlying field refers to a non-existent type declaration.MalformedParameterizedTypeException: if the generic signature of the underlying field refers to a parameterized type that cannot be instantiated for any reason. Below programs illustrate getGenericType() method: Program 1: Java // Java program to illustrate // getGenericType() method import java.lang.reflect.Field; import java.lang.reflect.Type; public class GFG { // initialize field private static int number; public static void main(String[] args) throws NoSuchFieldException { // get Field object Field field = GFG.class .getDeclaredField("number"); // apply getGenericType() method Type type = field.getGenericType(); // print Results System.out.println( "Type class: " + type.getClass()); System.out.println( "Type name: " + type.getTypeName()); } } Output:Type class: class java.lang.Class Type name: int Program 2: Java // Java program to illustrate // getGenericType() method import java.lang.reflect.Field; import java.lang.reflect.Type; public class GFG { // initialize field final static String value = "Geeks"; public static void main(String[] args) throws NoSuchFieldException { // get Field object Field field = GFG.class .getDeclaredField("value"); // apply getGenericType() method Type type = field.getGenericType(); // print Results System.out.println( "Type class: " + type.getClass()); System.out.println( "Type name: " + type.getTypeName()); } } Output:Type class: class java.lang.Class Type name: java.lang.String References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getGenericType-- Comment More infoAdvertise with us Next Article Field getType() 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 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 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 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 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 getAnnotatedType() method in Java With Examples 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 typ 2 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 Like