Java reflect Flashcards
What is reflect
In computer science, reflection is the ability of a process to examine, introspect, and modify its own structure and behavior. Reflection is an API that is used to examine or modify the behavior of methods, classes, interfaces at runtime. The required classes for reflection are provided under java.lang.reflect package. Reflection gives us information about the class to which an object belongs and also the methods of that class which can be executed by using the object. Through reflection, we can invoke methods at runtime irrespective of the access specifier used with them.
Java Reflect core classes
- Class
- Constructor
- Method
- Field
Class类
Class type’s object is the description of other classes: structure, ‘class and interface’;
through the object we can get the class’s constructor, member method and fields.
Class类 core method
method usage
Class.forName() 静态方法,get class objection
classObj.newInstance() 用默认构造函数,创建对象
classObj.newConstructor() 获得构造函数对象
classObj.newMethod() 获得method对象
classObj.newField() 获得field对象