开发者

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

Why is the JavaBean standard set to us开发者_Python百科e 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.


Reads better. Compare:

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

or even

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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜