0
我尝试通过该属性的名称使用javabeans反射设置/获取属性值。JAVABEANS错误找不到符号
当我尝试编译此代码
class TestReflection
{
public TestReflection()
{
}
private Integer field;
public Integer getField()
{
return this.field;
}
public void setField(Integer x)
{
this.field = x;
}
}
// .
// .
// .
TestReflection ref = new TestReflection();
Object value = new PropertyDescriptor("field",
ref.class).getReadMethod().invoke(ref); // ERROR
我得到这个错误:
Test.java:84: error: cannot find symbol
ref.class).getReadMethod().invoke(ref);
symbol: class ref
如何解决这个错误?