Field getType() method in Java with Examples Last Updated : 26 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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 a Class object that identifies the declared type. Below programs illustrate getType() method: Program 1: Java // Java program to demonstrate getType() method import java.lang.reflect.Field; public class GFG { public static void main(String[] args) throws Exception { // Get the marks field object Field field = User.class.getField("Marks"); // Apply getType Method on User Object // to get the Type of Marks field Class value = field.getType(); // print result System.out.println("Type" + " is " + value); // Now Get the Fees field object field = User.class.getField("Fees"); // Apply getType Method on User Object // to get the Type of Fees field value = field.getType(); // print result System.out.println("Type" + " is " + value); } } // sample User class class User { // static double values public static double Marks = 34.13; public static float Fees = 3413.99f; public static double getMarks() { return Marks; } public static void setMarks(double marks) { Marks = marks; } public static float getFees() { return Fees; } public static void setFees(float fees) { Fees = fees; } } Output: Type is double Type is float Program 2: Java // Java program to demonstrate getType() method import java.lang.reflect.Field; import java.time.Month; public class GFG { public static void main(String[] args) throws Exception { // Get all field objects of Month class Field[] fields = Month.class.getFields(); for (int i = 0; i < fields.length; i++) { // print name of Fields System.out.println("Name of Field: " + fields[i].getType()); } } } Output: Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month Name of Field: class java.time.Month References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getType-- 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 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 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 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 getShort() method in Java with Examples The getShort() method of java.lang.reflect.Field used to get the value of short which has to be static or instance field type. This method also used to get the value of another primitive type convertible to type short via a widening conversion. When a class contains a static or instance short field 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 getLong() method in Java with Examples The getLong() method of java.lang.reflect.Field used to get the value of long which has to be static or instance field type. This method also used to get the value of another primitive type convertible to type long via a widening conversion. When a class contains a static or instance long field and 3 min read 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 set() method in Java with Examples The set() method of java.lang.reflect.Field is used to set the value of the field represented by this Field object on the specified object argument to the specified new value passed as parameter. The new value is automatically unwrapped if the underlying field has a primitive type. If the field is s 4 min read KeyStore getType() method in Java with Examples The getType() method of java.security.KeyStore class is used to get the type of this keystore. Syntax: public final String getType() Parameter: This method accepts nothing as a parameter. Return Value: This method returns the type of this keystore. Note: All the programs in this article wonât run on 3 min read Like