In-depth exploration of Java reflection mechanisms

Source: Internet
Author: User

This article is excerpted from Java reflection tutorial

Through the reflection mechanism of Java, you can obtain information such as class, interface, fields, and methods at runtime even if you do not know information such as class name and method name during compilation, you can also create new instances, call methods, and obtain/set attribute values.

This article describes the basic knowledge of the Java reflection mechanism, including: array (arrays), annotation (annotations), generic (generics), and dynamic proxy (Dynamic proxy ), and dynamic class loading and reloading ).

This article also introduces some special techniques, including getting the getter method of a class and accessing the private attributes and methods of a class.

This article introduces Java reflection based on JDK 6.

Example

First, let's look at an example of Java reflection.

 
Import Java. lang. reflect. method; public class hellojava {public static void main (string [] ARGs) {method [] Methods = hellojava. class. getmethods (); For (method M: Methods) system. out. println (M. getname ());}}

Result:

Mainwaitwaitwaitpolicstostringhashcodegetclassnotifypolicyall

This article will be divided into the following parts to introduce the reflection mechanism of Java

    • In-depth exploration of Java reflection mechanism (class)
    • Non-in-depth exploration of Java reflection mechanisms (constructors)

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.