Initial knowledge of Java reflection mechanism

Source: Internet
Author: User

Reflection is the greatest manifestation of dynamic nature

The runtime can change the effect that the compilation period determines is the dynamic nature of the programming language.

Java Dynamics can use the reflection mechanism to explore classes with unknown compile time, Java reflection Count is one of the characteristics of Java program

It allows a running Java program to check itself or self-audit and to directly manipulate the internal properties of the program

Use the steps in a general design application: First, the class object that gets the classes to manipulate

The second is to explore the information in class (attribute construction method)

The third is to use the information in the class object, such as: Use the constructor to produce the object's instance object ' using the property of the Get/set method method call, etc.

In the reflection mechanism, the class object can be generated according to the instance object, or it can be based on the type name. Gets a class object that can also get a class object based on the full name of the string

However, be sure to add a try catch statement to prevent the object from being fetched when you use it

It is also possible to manipulate the object's properties and constructs and the methods inside the object with its object name.

such as GetFields (). GetMethods (). GetConstructors (). You can get the public properties, methods, and constructs of the object

and by Getfdeclaredfields (). Gerdeclaredmethods () getdeclaredconstructors () to get information about the properties, methods, and constructors of class classes

Initial knowledge of Java reflection mechanism

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.