首页 > 编程语言 > 详细

JAVA反射机制-反射机制的相关API

时间:2020-04-25 00:10:39      阅读:47      评论:0      收藏:0      [点我收藏+]

 

一、通过一个对象获得完整的包名和类名

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());
    }
}

 

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://www.cnblogs.com/qq3511107946/p/12770892.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!