First, Reflection
a) refers to a class that can be used for runtime loading, discovery, and use of completely unknown during compilation
Second, Characteristics of Reflection
a) program running state, you can dynamically load a class with only one name loaded class All methods and properties of this class for any class object,
Third, Reflective notation ( Gets an object of that class through reflection )
a) person person= (person) class.forname ("Com.example.Person");
Four, for any class that you want to dynamically load, run the class, you must first obtain the corresponding Class
Five, Get Class the method
a) getclass ();
b) class.forname ();( most commonly used )
c) . Class
Six, the effect of the reflection mechanism:
a) Dynamically loading classes, dynamically fetching the information of the class (properties, methods, constructors);
b) dynamically constructing objects
c) Any method, constructor, that dynamically invokes classes and objects
d) dynamic invocation and Processing properties
e) get generic information
f) handling annotations
Seven, how the reflection mechanism introduces generics
a) java Span style= "font-family: Song body; Font-size:18pt "", java javac
i. Ensure that data security is exempt from the hassle of forcing class conversions.
b) Once the compilation is complete, all types related to generics are wiped out
Eight, performance problems of reflection mechanism
a) setaccessible switch for security check
i. Java language access check
ii. Java language access check. Not for true
You can access the false will not be accessible.
b) Improved reflection efficiency if security checks are disabled
Nine, in order to cater for actual development through reflection, Java has added
a) parameterizedtype: represents a parameterized type (for example, collecion<string>)
b) genericarraytype: an array type that represents an element type that is a parameterized type or a type variable
c) typevariable: Common Parent interface for various types of variables
d) wildcardtype: represents I a wildcard type expression
The reflection mechanism in Java