Java basic reflection and java basic reflection

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.