The JavaBeans methods’ signature’s has to follow certain conventions such as set…/get… and such. They have a convention for is…for instance isEven() could be a method for an Integer class to test a boolean. But then I wonder why not has… is also a legal identifier since it makes sense to me to test what something has e.g. hasCar() for a Person class or likewise.
Do you understand my question? What do you think?
Well, the general convention is to use
get...andset...and thusis...is just an exception for booleans. Foris...the convention is easy: you need to return a boolean, can skip the getter and the corresponding setter will take a boolean parameter as well.A convention for
has...would be more difficult:has...would return a boolean but you’d still need a getter and setter which deal with different types. Thushas...is no replacement forget...as opposed tois...and since that part of the JavaBeans convention normally only is about getters and settershas...doesn’t fit in there.From the JavaBeans spec:
Any property being accessed using
has...would not be persistent nor be accessed by its getter method.Example: if a person has a
carproperty, you’d expect to have agetCar()accessor.hasCar()wouldn’t be an accessor since the derived propertyhasCarwould need an accessor namedgetHasCar()orisHasCar(). Ifhaswas an accessor prefix, the property would have the conflicting namecar.