Java Field.getType()
Syntax
Field.getType() has the following syntax.
public Class <?> getType()
Example
In the following code shows how to use Field.getType() method.
//w w w. j av a 2 s . c o m
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class Main{
public static void main(String[] args) {
Field[] fields = java.lang.Integer.class.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
Class type = f.getType();
System.out.println(type.getCanonicalName());
}
}
}
The code above generates the following result.