lundi 6 avril 2015

JAVABEANS error cannot find symbol

I try to use javabeans reflection for set/get value of property by name of that property.


When I try to compile this code



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


I got this error:



Test.java:84: error: cannot find symbol
ref.class).getReadMethod().invoke(ref);
symbol: class ref


How can I fix that error?






Aucun commentaire:

Enregistrer un commentaire