public class Emp {
private String employeeId;
private String employeeName;
private double employeeSalary;
public String getEmployeeId() {
return employeeId;
}
public String getEmployeeName() {
return employeeName;
}
public double getEmployeeSalary() {
return employeeSalary;
}
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public void setEmployeeSalary(double employeeSalary) {
this.employeeSalary = employeeSalary;
}
@Override
public String toString() {
return "Emp [employeeId=" + employeeId + ", employeeName="
+ employeeName + ", employeeSalary=" + employeeSalary + "]";
}
}
这是一个示例类。用户将输入该班级的名称。根据用户输入我想找到getter和setter方法及其类的详细信息。为此,我使用下面的代码。但它没有显示employeeId,employeeName,employeeSalary的gettes和setter。
BeanInfo info;
info = Introspector.getBeanInfo(c.getClass());
MethodDescriptor[] md = info.getMethodDescriptors();
for (MethodDescriptor methodDescriptor : md) {
LOGGER.info("Method-"+methodDescriptor.getMethod().getName());
}
我正在尝试使用上面的代码读取类的方法,但它没有显示声明字段的getter和setter。
答案 0 :(得分:0)
我可能需要Field类。
Field类提供有关类或接口的单个字段的信息和动态访问。反射字段可以是类(静态)字段或实例字段。
使用Field[]
。
以下是Package for it
import java.lang.reflect.Field;