如何获取java.lang.Class对象
@suppresswarnings('all )//新闻警告
公共类deam {
publicstaticvoidmain (string [ ] args ) throws InstantiationException,IllegalAccessException,IllegalArgumentException,intion
try {
加载//类后,jvm会为相应类创建类对象,并将类的整个信息放入相应的类对象中
class c=class.forname (cn.sxt.in.demo );
系统. out.println (c;
//获取类名. classclass对象
Class strc=String.class;
//对象.获取getClass () Class对象
String path='a ';
Class strc2=path.getClass (; //与上面String中的Class对象相同
system.out.println(strc==strC2 );//真
Class intc=int.class; 获取//int的Class对象
int[] a=new int[10];
int[] a2=new int[20]; //所得数组中的所有Class对象都相同
String[] a3=new String[10]; //在不同类型的数组和不同维的数组中生成的Class对象不同
system.out.println(a.getclass ().hashCode ) );
system.out.println(a3.getclass ().hashCode ) );
}catch(classnotfoundexceptione ) )
e .打印堆栈跟踪(;
}
}
}