我们知道 reflection是java的高级 特性之一。在底层框架中被频繁使用。
比如 JDBC加载数据库的JDBC driver. Spring中加载Bean对象。
首先 什么是反射?
反射就是在运行状态能够动态的获取该类的属性和方法,并且能够任意的使用该类的属性和方法,这种动态获取类信息以及动态的调用对象的方法的功能就是反射。
反射执行原理:
我们知道 对于类对象的编译 一般是
.java file compile to .class file and then loaded to JVM (class loader) to machine code.
so if we can get that .class file then we can use it whatever we want.
and there are few ways to get it:
.class or .getClass().