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。