如果一个boolean类型JavaBean有两个get方法(boolean默认是is方法): public boolean getBool() {
return true;
}
public boolean isBool() {
return false;
}
问题:页面使用el表达式(即,${bean.bool}),输出结果是哪一个呢? 答案:是isBool返回的。 false
也就是说,isBoolean()方法优先于getBoolean()方法,如果没有isBoolean()方法,才找getBoolean()方法。
而Boolean则只能使用get和set方法取得属性。
private boolean b;
private Boolean bb;
public boolean isB() { return b; }
public void setB(boolean b) { this.b = b; }
public Boolean getBb() { return bb; }
public void setBb(Boolean bb) { this.bb = bb; }