例子:
public class StaticStuff {
public static void main(String[] args) {
StaticStuff heStaticStuff = new StaticStuff();
System.out.println(StaticStuff.class);
System.out.println(heStaticStuff.getClass());
try {
System.out.println(Class.forName("com.lz.crm.StaticStuff"));
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行结果:
class com.lz.crm.StaticStuff
class com.lz.crm.StaticStuff
class com.lz.crm.StaticStuff
三种方式:
- 方法1:类型.class,例如:String.class
- 方法2:对象.getClass(),例如:"hello".getClass()
- 方法3:Class.forName(),例如:Class.forName("java.lang.String")