package cn.itcast.day2;
public class ReflectTest {
public static void main(String[] args) throws Exception {
String str1 = "abc";
Class cls1 = str1.getClass();
Class cls2 = String.class;
Class cls3 = Class.forName("java.lang.String");
System.out.println(cls1 == cls2);
System.out.println(cls1 == cls3);
System.out.println(cls2 == cls3);
System.out.println(cls1.isPrimitive());//判断是不是基本数据类型
System.out.println(int.class.isPrimitive());//yes
System.out.println(int.class == Integer.class);//false
System.out.println(int.class == Integer.TYPE);//true Type属性实际上指的就是基本数据类型
System.out.println(int[].class.isPrimitive()); //false
}
}
原文地址:http://www.cnblogs.com/siashan/p/3840947.html