JAVA反射机制-反射机制的相关API
Posted qq3511107946
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于JAVA反射机制-反射机制的相关API的主要内容,如果未能解决你的问题,请参考以下文章