1、通过调用某个对象的getClass()方法获取;
package test; public class Test { public static void main(String[] args) { Test test = new Test(); Class extends Test> tClass = test.getClass(); System.out.println(tClass.getName()); } }
执行结果:
test.Test
2、通过调用Class.forName()来读取指定的类名来获取;
package test; public class Test { public static void main(String[] args) throws ClassNotFoundException { Class> c = Class.forName("test.Test"); System.out.println(c.getName()); } }
执行结果:
test.Test
3、直接用类.class来获取;
package test; public class Test { public static void main(String[] args) { Class> c = Test.class; System.out.println(c.getName()); } }
执行结果:
test.Test
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)