Reflection (reflection) (class loader)

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

Reflection (reflection)

Reflection : In a java class during operation, the properties of this class for any call, for objects of this class can invoke any call any method which dynamically acquires the attribute information, and the dynamic behavior of the called method is called reflection

1. Four types of loading

Delay load (will only be loaded when new objects)

	Class c = 实体对象.class;
	c.newInstance();
	实体对象 et = new 实体对象();
	Class c = et.getclass();

Timely loading (static block will print immediately)

	Class c = Class.forName("对象路径");

Acquired by the class loader (system loader) (also belonging to delay loading)

	ClassLoader loader = ClassLoader.getSystemClassLoader();
	Class c = loader.loadClass("对象路径");
2. Get all the class of a parent
	Class c = 类.class;
	while(c!=null){
			c = c.getSuperclass();
	}
3. Basis and packaging
包装类
	Class c1 = Integer.class;
	c1.getName==java.lang,.Integer
	
基础类	
	Class c1 = int.class;
	c1.getName==int
	
在jdk1.5版本之后
	Class c3 = Integer.TYPE;
	c3==int

Knowledge summary

加载机制分为1.向上委托 2.向下通知
1.向上委托:系统加载器不会马上加载,会向上委托,给扩展加载器与不会马上加载,会向上委托给引导加载器
1.向下通知:如果扩展加载器中有这个类型会直接加载,若没有通知ExtclassLoader加载,若ExtclassLoader
没有则会通知AppclassLoader加载,若AppclassLoader也没有则会报错

Guess you like

Origin blog.csdn.net/D1206/article/details/94604943