Home > Java > javaTutorial > How to use reflection API to manipulate information in java

How to use reflection API to manipulate information in java

PHPz
Release: 2023-04-30 13:34:06
forward
885 people have browsed it

1. Obtaining the class object you want to operate is the core of reflection. We can call any class method through the class object.

2. Calling the class method is the use stage of reflection.

3. Use reflection API to operate this information.

Example

class Worker{
/*两个public构造方法*/
public Worker(){
count++;
}
public Worker(String name){
super();
this.name = name;
}
/*两个private构造方法*/
private Worker(String name,int age){
super();
this.name = name;
this.age = age;
}
private Worker(int age){
super();
this.age = age;
}
/*两个private属性*/
private String name;
private int age;
/*一个public属性*/
public String parents;
/*一个private static属性*/
private static int count;
/*一个 public static属性*/
public static String address;
/*两个public方法*/
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
/*两个private方法*/
private int getAge(){
return age;
}
private void setAge(int age){
this.age = age;
}
/*两个public static方法*/
public static void printAddress(String address){
System.out.println("printAddress==="+address);
}
public static void printAddress(){
System.out.println("printAddress===default");
}
/*两个private static方法*/
private static void printlnCount(int count){
System.out.println("printCount==="+count);
}
private static void printlnCount(){
System.out.println("printCount===000");
}
@Override
public String toString(){
return "这是一个Worker实例:name="+name+",age="+age;
}
}
Copy after login

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

Related labels:
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
Latest Issues
Laravel adds Api namespace
From 1970-01-01 08:00:00
0
0
0
What does the Laravel api manual do?
From 1970-01-01 08:00:00
0
0
0
javascript - About Baidu Map API calling issues
From 1970-01-01 08:00:00
0
0
0
How to get the Baidu map api
From 1970-01-01 08:00:00
0
0
0
laravel dingo/api installation and configuration
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template