Mark Robinson
Mark Robinson

Reputation: 3165

Why is the JavaBean standard to is for booleans instead of get

Why is the JavaBean standard set to use the prefix is- for a getter instead of get-?

It seems to be a really out place for a uniform naming convention, especially for only a single getter for a single type.

Upvotes: 0

Views: 405

Answers (2)

Buhake Sindi
Buhake Sindi

Reputation: 89169

You can have "get" on a boolean too, it's allowed. I think they did this for readability. you say

if (bean.isImmutable()) { // Better 

rather than

if (bean.getImmutable()) { //Get what? 

Also, if you use reflection on JavaBeans and you see a getter method starting with a "is", you can do a type check to see if the return type of this getter method is a boolean (because only boolean have the special case of "is" getter method).

Upvotes: 4

iluxa
iluxa

Reputation: 6969

Reads better. Compare:

  • Girl.getBeautiful()
  • Girl.isBeautiful()

or even

  • Coin.getGold()
  • Coin.isGold()

Upvotes: 6

Related Questions