Home > Java > JavaBase > what is reflection in java

what is reflection in java

王林
Release: 2019-11-12 09:36:04
Original
4278 people have browsed it

what is reflection in java

#What is reflection in java?

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.

Java reflection method

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 can obtain it through the Class object.

Method 1:

what is reflection in java

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

what is reflection in java

Method 2:

what is 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.

what is reflection in java

Recommended tutorial: java tutorial

The above is the detailed content of what is 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