JavaBeans -- getters with Boolean type
When you want to create a boolean property in a Java Bean (let’s name it
visible), you most likely would want to use
a boolean type variable and create accessors for it.
Well, if you use a boolean primitive it is allowed to create a getter in one of two manners:
public boolean getVisible()
public boolean isVisible()
Notice that the second option is only allowed when your property is a
boolean primitive. Therefore, when your
property is a
Boolean object, the getter should be in only one form:
public Boolean getVisible()
It’s easy to make such a mistake, but JEE EL (Expression Language) is very strict about that (which is understandable).
So, I guess it’s the best just to use the
get...() form of a accessor. If you have a code-style language-related
problem with accepting
getVisible() construct in your code, just try translating your property form from question
into statement form like:
Boolean visilibity; public Boolean getVisibility();
Sounds better, doesn’t it?