Java basic reflection and java basic reflection
Compile-time vs Run-Time
"Compile-time" refers to the period in which java code is compiled into a class file without memory.
"Compile-time type" indicates that the compile-time type is determined by the type used to declare the variable.
"RunTime" refers to the period in which class files are executed by the Java Virtual Machine, involving memory.
"Runtime type" means that the runtime type is determined by the object actually assigned to the variable.
Dynamic binding
During compilation, a member method of the declaration type is called, and a Member method of the actual type is called during runtime.
Note:Call a member variable of the reference typeBoth "compile-time" and "RunTime" are called.Member variables of the actual type.
What is reflection?
When runningFor any class, you can know all the attributes and methods of this class; for any object, you can call any of its methods and variables.
Use of Class reflection to obtain the class
Create a Class Object
Call methods or variables in class objects
Reflection application in Android
Use the original java reflection mechanism to call Resources
Is it awesome !!!
Create an Activity object during Activity startup
In ActivityThread of the Activity startup class, an Activity is started as follows:
How is the newActivity of mInstrumentation implemented?
In Android, manifest file loading and layout loading are also injected to java code through reflection.