An overview of the reflection mechanism in Java reflection learning

Source: Internet
Author: User

I. Background overview of reflection mechanism

1. Reflection (reflection) is a key property of Java as a dynamic language

2, reflection mechanism refers to the program at runtime to obtain any class of all internal information

Second, the reflection mechanism realizes the function summary

1, as long as the full name of the given class, you can get all the information of the class through reflection

2, the program is running is able to get any object belonging to the class object

3. At run time, you can get all the properties of a class and manipulate it

4, at run time can get the class, all the methods of the parent class and call

5, the current mainstream framework struts2, srping, hiberate and other framework of the core functions are through the Java reflection mechanism to achieve

Mechanism and realization of reflection-related objects

1. The Mechanism and implementation of class object

(1) Class Object Overview

Class is the type of classes

(2) Class common methods

GetName () Gets the full name of the class

Getdeclaredfields () gets all the properties in the class

Getdeclaredmethods () gets all the methods in the class

GetConstructors () Get the method of constructing class

Newinstance () instantiating an object of a class

Wait a minute..

2. Three ways to get classes

(1) Class.forName (String className),ClassName must be the full path of the class

(2) Book book = new book (); Book.getclass ();

(3) Book.class;

In the Java reflection mechanism, there are many important objects, such as Field,method, which are not described here, and can be viewed Javaapi to understand its functionality.

An overview of the reflection mechanism in Java reflection 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.