Summary of Reflections in Java

Source: Internet
Author: User

Reflection is the acquisition of runtime class information, which is the class information in the constant area.

To obtain the class information, it is necessary to rely on, or how the system specifies that you want to get that kind of information,

Class information in Java is an object of the class class, it is a Java class abstraction, in other words it represents a ' class ' (the class itself is an abstraction of things, in the program it represents this thing, class is an abstraction of this class),

Three ways to get it,

1). String Class.forName of Class name

2). According to the class acquisition, Integer.class

3). Gets (new Integer ()) according to the object. GetClass

It is worth mentioning that the class of all class objects is still class

Here's a look at this class,

The first class implements the Type,type and does not have any function, is an empty interface, it just represents this is a type

 Package Java.lang.reflect;  Public Interface Type {}
View Code

In addition, it implements the Annotatedelement interface, which indicates that this is an element that can use annotations.

 Package Java.lang.reflect; Import java.lang.annotation.Annotation;  Public Interface annotatedelement {     booleanextends annotation> annotationclass);     extends Annotation> T getannotation (class<t> annotationclass);    Annotation[] Getannotations ();    Annotation[] Getdeclaredannotations ();}
View Code

The Genericdeclaration interface, which indicates that this is a generic element that gets an typevariable array representing the generic parameter, Typevariable implements the type interface, that is, the generic parameter is also a type

 Package Java.lang.reflect;  Public Interface genericdeclaration {    public typevariable<?>[] gettypeparameters ();} 
View Code

The entire class relationship is as follows:

field (Fields), Method (methods), Constructor (construction method) are aggregated under class

All three members inherit from member, which is the reflection member.

 PackageJava.lang.reflect; Public InterfaceMember { Public Static Final intPublic = 0;  Public Static Final intDeclared = 1;  PublicClass<?>Getdeclaringclass ();  PublicString getName ();  Public intgetmodifiers ();  Public Booleanissynthetic ();}
View Code

Summary of Reflections in Java

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.