1
找到getter和setter方法我有这样的Java反射
public class Student
{
private String reference;
private String aPlaceAt;
//methods generate by Netbeans Eclipse generates the same methods
public String getaPlaceAt(){return aPlaceAt;}
public void setaPlaceAt(String aPlaceAt){this.aPlaceAt = aPlaceAt;}
public String getReference(){return reference;}
public void setReference(String reference){this.reference = reference;}
}
类后,我需要通过reflection
来查找每个属性的getter和setter方法我用下面的代码
public Method findSetterFor(final Class clazz,final String propertyName) throws Exception
{
return new PropertyDescriptor(propertyName,clazz).getWriteMethod();
}
for(final Field field:clazz.testClazz.getDeclaredFields())
System.out.println(field.getName()+" "+clazz.findSetterFor(clazz.testClazz,field.getName()));
他们返回正确的二传手参考,但为财产aPlaceAt
投掷
Exception in thread "main" java.beans.IntrospectionException: Method not found: isAPlaceAt
为什么是APP呢?不应该是
public void setaPlaceAt(String aPlaceAt){this.aPlaceAt = aPlaceAt;}?
或为什么我做错了?如何完成它谢谢?
我认为getter和setter方法是产生正确地根据在SO其他岗位而这个链接
的方法产生由Netbeans and Eclipse and intellij
UPDATE 这里是另一个热点论坛关于它同样的问题,请查看
它们是由netbeans产生的 – chiperortiz
@chiperortiz嗯。 Netbeans并没有遵循bean的命名规则。 –
@chiperortiz你也需要改变我的答案中显示的吸气剂。 –