![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
反射
别拦着我,我要学习
这个作者很懒,什么都没留下…
展开
-
静态代理与动态代理例子
静态代理: 特点:代理类和被代理类在编译期间,就确定下来了 interface ClothFactory{ void produceCloth(); } //代理类 class ProxyClothFactory implements ClothFactory{ private ClothFactory factory;//用被代理类的对象进行实例化 public ProxyClothFactory(ClothFactory factory){ this.factor原创 2020-10-29 16:47:00 · 61 阅读 · 0 评论 -
获取运行时类的结构
通过反射创建对应的运行时类的对象 public void test1() throws IllegalAccessException, InstantiationException { Class<Person> clazz = Person.class; /* newInstance():调用此方法,创建对应的运行时类的对象 内部调用了运行时类的空参构造器 要想此方法正常的创建运行时类的对象,要求: 1.运行时类必须提供空参的构造器 2.原创 2020-10-29 11:52:25 · 77 阅读 · 0 评论 -
了解类的加载器
public void test1(){ //对于自定义类,使用系统类加载器进行加载 //系统类加载器 ClassLoader classLoader1 = ClassLoaderTest.class.getClassLoader(); System.out.println(classLoader1);//sun.misc.Launcher$AppClassLoader@18b4aac2 //调用系统类加载器的getParent():获取扩展类加载器 Clas原创 2020-10-28 18:51:45 · 55 阅读 · 0 评论 -
反射基础
关于java.lang,Class类的理解 类的加载过程: 程序经过javac.exe命令以后,会生成一个或多个字节码文件(.class结尾)。 接着我们使用java.exe命令对某个字节码文件进行解释运行。相当于将某个字节码文件加载到内存中。此过程称为类的加载。 加载到内存中的类就成为运行时类,此运行时类,就作为Class的一个实例。 换句话说,Class的实例就对应着一个运行实类 加载到内存中的运行时类,会缓存一定的时间。在此时间之内,我们可以通过不同的方式来获取此运行时类 获取Class的实例的方式原创 2020-10-28 18:39:25 · 50 阅读 · 0 评论