Java Reflection meaning

Source: Internet
Author: User

The Java reflection mechanism is in the running state, for any class, can know all the properties and methods of this class, for any object, can invoke its arbitrary methods and properties; This dynamic acquisition of information and the ability to dynamically invoke object methods is called the reflection mechanism of the Java language.

Java means that 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.

The Java Reflection mechanism provides the following functions: To determine the class to which any object belongs at run time, to construct an object of any class at run time, to determine the member variables and methods that any class has at run time, to invoke a method of any object at run time, and to generate a dynamic proxy.

。 When a class is loaded, or when the defineclass () of the Loader (class loader) is called by the JVM, the JVM automatically generates a Class object.

Class is the origin of the reflection story. For any class that you want to explore, you only have to create a class object for it, and then you can invoke more than 10 reflection APIs through the latter. These APIs will be unveiled in one by one of later adventures.

Java allows us to generate the corresponding class object for a class from a variety of pipelines. Figure 2 is a collation. Example of a class object birth pipeline: 1) using getclass () Note: Each class has this function, string str = "ABC"; Class C1 = Str.getclass (); 2) using Class.getsuperclass () button b = New button (); Class C1 = B.getclass (); Class C2 = C1.getsuperclass (); 3) Use the static method------Class.forName () (most commonly used) class C1 = Class.forName ("java.lang.String "); Class C2 = class.forname ("Java.awt.Button"); Class C3 = Class.forName ("Java.util.linkedlist$entry"); Class C4 = class.forname ("I"); Class C5 = Class.forName (". Class"), 4) using the TYPE syntax of primitive wrapper classes class C1 = Boolean.type; Class C2 = Byte.type; Class C3 = Character.type; Class C4 = short.type; Class c5 = integer.type; Class C6 = long.type; Class c7 = Float.type; Class C8 = Double.type; Class C9 = void.type;    
    • Java Reflection-Importnew January 24, 2016-After the class is loaded, a class-type object is generated in the heap memory (a class has only a single class object), which contains the complete class structure information, and the class object is like a mirror,... www.importnew.com/176 .... -Baidu Snapshot

Java Reflection meaning

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.