JAVA反射机制-反射机制的相关API
2021-02-08 15:15
标签:https snippet gic get void instance over ref argument https://www.cnblogs.com/lzq198754/p/5780331.html https://www.logicbig.com/how-to/code-snippets/jcode-reflection-class-getgenericsuperclass.html https://stackoverflow.com/questions/6363346/getting-type-arguments-of-parameterized-class https://stackoverflow.com/questions/3437897/how-do-i-get-a-class-instance-of-generic-type-t https://ifeve.com/syntethic-and-bridge-methods/ https://blog.csdn.net/fangqun663775/article/details/78960545 JAVA反射机制-反射机制的相关API 标签:https snippet gic get void instance over ref argument 原文地址:https://www.cnblogs.com/qq3511107946/p/12770892.html一、通过一个对象获得完整的包名和类名
package net.xsoftlab.baike;
public class TestReflect {
public static void main(String[] args) throws Exception {
TestReflect testReflect = new TestReflect();
System.out.println(testReflect.getClass().getName());
// 结果 net.xsoftlab.baike.TestReflect
}
}
二、实例化Class类对象
package net.xsoftlab.baike;
public class TestReflect {
public static void main(String[] args) throws Exception {
Class> class1 = null;
Class> class2 = null;
Class> class3 = null;
// 一般采用这种形式
class1 = Class.forName("net.xsoftlab.baike.TestReflect");
class2 = new TestReflect().getClass();
class3 = TestReflect.class;
System.out.println("类名称 " + class1.getName());
System.out.println("类名称 " + class2.getName());
System.out.println("类名称 " + class3.getName());
}
}
文章标题:JAVA反射机制-反射机制的相关API
文章链接:http://soscw.com/index.php/essay/52682.html