1.Can u express in a word what reflex is?
it’s a dynamic machanism which obtain field and method of class.
It’s applied to set/get field or method when jvm run-time.
2.which classes are relative with Reflex ?
Class
Field
Method
Constructor
Invoke
3.which classes are associated with Class?
public final class Class<T> implements java.io.Serializable,
GenericDeclaration,
Type,
AnnotatedElement
Class has implemented:
java.io.Serializable
GenericDeclaration,
Type,
AnnotatedElement.
Class method commonly:
asSubclass:seen as subclass
cast:compulsively
getClassLoader()
getClasses():getAllClasses public as Arrays within class
getDeclaredClasses():include no-public class
forName(String Classname):obtain class object by ClassName
getPackage:
getSimpleName:
getSuperClass:
getInterfaces:
newInstance():create newInstace of class
getField(String name):getField by Field-name public
getFields():getAllField public
getDeclaredField(String name):obtain allField(contain no-public such as private) by name
getDeclaredFields():get all field as Arrays(include no-public such as private)
Mehtod and Field’s method regular
Field.equals(Object o)
Field.set(Object obj,value)
Field.get(Object obj)
Method.invoke(Object obj,InitialnizationArguments args)
Tips:
getDeclaredXXX can obtain private method/field.
and Additional line
Object o = Class.getDeclaredMethod/constructor/Field(methodName,args.class)
o.setAccessible(true);
If there is explicit permission validation in the source code, and your application cannot obtain it, it is advisable not to waste time reflecting.
Reflection is the soul of frame design.