Java Reflection Mechanism Learning

Source: Internet
Author: User

JavaWhat is reflection?

Official definition: The JAVA reflection mechanism is in the running state , for any class, can know all the properties and methods of the class ; Any one of its methods and properties can be called for any object ; This dynamic acquisition of information about a class and the ability to dynamically invoke the object's methods are known as the reflection mechanism of the Java language.

Understanding: Gets A feature of a running Java object.

JavaWhat is the reflection function?

1. Determine the class to which any object belongs at run time;

2. Constructs an object of any class at run time;

3. Determine the member variables and methods of any class at run time;

4. Method of invoking any object at run time;

5. Generate the dynamic agent.

Implementing JavaWhat are the reflected classes?

1.Class: It represents classes and interfaces in a running Java application
2.Field: Provides information about the properties of a class or interface, as well as the dynamic access rights to it
3.Constructor: Provides information about a single construction method of a class and access to it
4.Method: Provides information about a method in a class or interface

Note: The class class is the most important feature class in Java reflection, and all information that gets the object (including: Method/attribute/constructor/access) needs it to implement

How to do JavaReflective programming?

1. First get the class object

There are three ways to accomplish this:

Class C1 = Test.class;
Class C2 = class.forname ("Test");
  Class C3 = New Test (). GetClass ();

2. Then call the methods in the class object to get information about the properties, methods, and construction methods in a class.

Java Reflection Mechanism Learning

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.