Code: Select all
public class Bean {
protected Boolean happy;
public Boolean isHappy() {
return happy;
}
public void setHappy(Boolean happy) {
this.happy = happy;
}
}
< /code>
Der folgende Code funktioniert gut: < /p>
Bean bean = new Bean();
BeanUtils.setProperty(bean, "happy", true);
< /code>
Versucht jedoch, die Happy < /code> Eigenschaft wie SO zu erhalten: < /p>
Bean bean = new Bean();
BeanUtils.getProperty(bean, "happy");
< /code>
Ergebnisse in dieser Ausnahme: < /p>
Exception in thread "main" java.lang.NoSuchMethodException: Property 'happy' has no getter method in class 'class Bean'
< /code>
Ändern alles in einen primitiven booleschen < /code> Ermöglicht sowohl den Set als auch den Aufruf zum Laufen. Ich habe diese Option jedoch nicht, da es sich um Klassen handelt. Ich gehe davon aus, dass dies geschieht, weil die Java -Bean -Bibliotheken nur eine IS