package Test;
?
/**
?* 通过反射获取类属性的类型
?* @author test
?*
?*/
public class OtherTest {
?
private static int i = 1;
private static String name = "wang";
?
public static void main(String[] args) throws Exception {
?
System.out.println(OtherTest.class.getDeclaredField("i").getType());
System.out.println(OtherTest.class.getDeclaredField("name").getType());??
}
}
?
另:getDeclaredField是可以获取一个类的所有字段.?getField只能获取类的public 字段.