![]() |
VOOZH | about |
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:
Below programs illustrate getGenericType() method: Program 1:
Type class: class java.lang.Class Type name: int
Program 2:
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--