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

 

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

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

 

 

https://blog.csdn.net/briblue/article/details/73824058/

 

https://blog.csdn.net/briblue/article/details/54973413  一看你就懂,超详细java中的ClassLoader详解

 

====================================================================================================

java序列化的资料:

https://www.cnblogs.com/xdp-gacl/p/3777987.html

https://www.iteye.com/blog/jiangzhengjun-519256

https://blog.csdn.net/qq_31457665/article/details/82587942

序列化 ID
虚拟机是否允许反序列化,不仅取决于类路径和功能代码是否一致,一个非常重要的一点是两个
类的序列化 ID 是否一致(就是 private static final long serialVersionUID)

要想将父类对象也序列化,就需要让父类也实现 Serializable 接口。   --> 用测试下父类的序列化行为。


 

posted @ 2020-04-24 23:22  fjxszx_hss  阅读(147)  评论(0)    收藏  举报