Reflection class Loading

Source: Internet
Author: User

Reflection technology in Java: The runtime explores and uses classes that are not known at compile time.

The core principle of reflection: when the JVM loads a class, it stores the information of that class in a class object, which is also called the template object, and the JVM can retrieve all the information for that class by retrieving the object.

The JDK provides an API that allows the programmer to obtain class objects, which can cause the programmer to retrieve information about the class, even if the class is not implemented by a program or programmer.

There are 3 ways to get a class object.

1, by the type name of the class object, all types can get the class object, this method is not dynamic, to know the type name at compile time.

2, the object or instance object to get the class object (can only be non-abstract class and array type), abstract class, interface, void, the basic data type can not, thought that when writing code when the instance object has been obtained, so there is no dynamic.

3, it is the only dynamic embodiment that the class object (which only accepts classes and interfaces) is obtained through the string form of the full name of the classes. (Note: The full name of the class must be filled in, and the active load is completed before returning the class object)

Through filed can explore the properties, constructor can explore the structure, method can explore methods.

Explore the constructor can produce instance objects, using the Newinstance method can be to the object.

The method can be called through the Invoke method.

The filed can be evaluated and modified by the get and set methods.

Reflection is the third method of producing objects in Java, and only public parameterless constructs can be called when an object is produced. A private property is an Get,set method that invokes it in reflection. Reflection is the underlying implementation of Java, which actually destroys encapsulation.

Reflection class Loading

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.