[1] Java反射知识-->Spring IoC :http://www.iteye.com/topic/1123081
[2] Java动态代理-->Spring AOP :http://www.iteye.com/topic/1123293
[3] 属性编辑器,即PropertyEditor-->Spring IoC:http://www.iteye.com/topic/1123628
[4] XML基础知识-->Spring配置:http://www.iteye.com/topic/1123630
[5] 注解-->Spring配置:http://www.iteye.com/topic/1123823
[6] 线程本地变更,即ThreadLocal-->Spring事务管理:http://www.iteye.com/topic/1123824
[7] 事务基础知识-->Spring事务管理:http://www.iteye.com/topic/1124043
[8] 国际化信息-->MVC:http://www.iteye.com/topic/1124044
[9] HTTP报文-->MVC:http://www.iteye.com/topic/1124408
Class文件由类装载器装载后,在JVM中将形成一份描述Class结构的元信息对象,通过该元信息对象可以获知Class的结构信息:如构造函数、属性和方法等。Java允许用户借由这个Class相关的元信息对象间接调用Class对象的功能,这就为使用程序化方式操作Class对象开辟了途径。
- //①通过类装载器获取Car类对象
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class clazz = loader.loadClass("com.baobaotao.reflect.Car");
- //②获取类的默认构造器对象并通过它实例化Car
- Constructor cons = clazz.getDeclaredConstructor((Class[])null);
- Car car = (Car)cons.newInstance();
- //③通过反射方法设置属性
- Method setBrand = clazz.getMethod("setBrand",String.class);
- setBrand.invoke(car,"红旗CA72");
- Method setColor = clazz.getMethod("setColor",String.class);
- setColor.invoke(car,"黑色");
- Method setMaxSpeed = clazz.getMethod("setMaxSpeed",int.class);
- setMaxSpeed.invoke(car,200);
- return car;
- }
- public static void main(String[] args) throws Throwable {
- Car car = initByDefaultConst();
- car.introduce();
- }
- }
注意:获取当前类的类加载器ClassLoader loader = Thread.currentThread().getContextClassLoader();
注意:获取当前类的类加载器ClassLoader loader = Thread.currentThread().getContextClassLoader();
注意:获取当前类的类加载器ClassLoader loader = Thread.currentThread().getContextClassLoader();
注意:获取当前类的类加载器ClassLoader loader = Thread.currentThread().getContextClassLoader();