Home > Java > JavaBase > How to understand reflection in java

How to understand reflection in java

王林
Release: 2019-11-12 17:07:17
Original
6650 people have browsed it

How to understand reflection in java

What is reflection?

Java reflection means that in the running state, for any class, we can know what methods and attributes this class has. For any object, we can call its methods and properties. We call this function of dynamically obtaining object information and calling object methods a reflection mechanism.

Three ways of reflection

I need to tell you here that the so-called reflection is actually to obtain the bytecode file of the class, that is, the .class file, then we It can be obtained through the Class object.

Method 1:

How to understand reflection in java

This method is actually a method of Object. Class inherits Object, so we can use it directly.

How to understand reflection in java

Method 2:

How to understand reflection in java

Method 3:

It should be noted here that through the entire class Obtaining the Class object by path name will throw an exception. If the class cannot be found based on the class path, this exception will be thrown.

How to understand reflection in java

Recommended tutorial: java tutorial

The above is the detailed content of How to understand reflection in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template