Java Reflection mechanism

Source: Internet
Author: User

Java reflection mechanism, in the running state of Java, for any class, can know all his properties and methods, for any object, can call his methods and properties; This dynamic access to information, the function of dynamic call method is called the Java Reflection mechanism.

We can load, detect, and use classes that are completely unknown during compilation at runtime. In other words, a Java program can load a runtime to know the name of a class, learn its full construct (but not including the methods definition), and generate its object entities, or set values on its fields, or evoke its methods.

Java reflection using frequent methods

Class.forName ();//Load Java class

Clase method: Newinstance (), used to generate an instance of the class (no parameter constructs)

GetConstructor (), constructor with parameters, get method

Methods of constructor:

Newinstance (ARG), generating object entities

GetMethod (), Get method by method name and parameter type

Method: Invoke () execution method

GetField (), by property name, gets the attribute field

Method of field: Set (), Get ()

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.