布尔getter方法有效的JavaBean名 [英] Valid JavaBeans names for boolean getter methods
问题描述
我知道大多数变量名称将与是,如 isBlue()
,但有也是一个有效的preFIX,如 hasProperty()
?
I know most variable names will work with "is", such as isBlue()
, but is "has" also a valid prefix, like hasProperty()
?
推荐答案
According to the JavaBeans specification section 8.3.2:
布尔属性的
另外,对于
布尔属性,我们允许一个getter
方法匹配的模式:
公共布尔为<属性名>();
这个
isPropertyName
的方法可能是
提供的,而不是
获取LT;属性名>
的方法,也可能
除了提供到
获取LT;属性名>
的方法。在这两种
情况下,如果为<属性名>
方法
是一个布尔属性present然后
我们将使用为<属性名>
方法读取属性值。一个
例如布尔属性可能是:
公共布尔isMarsupial();
公共无效setMarsupial(布尔米);
Boolean properties
In addition, for boolean properties, we allow a getter method to match the pattern:
public boolean is<PropertyName>();
This "
isPropertyName
" method may be provided instead of a "get<PropertyName>
" method, or it may be provided in addition to a "get<PropertyName>
" method. In either case, if theis<PropertyName>
method is present for a boolean property then we will use the "is<PropertyName>
" method to read the property value. An example boolean property might be:public boolean isMarsupial(); public void setMarsupial(boolean m);
在换句话说,除非自那时以来,事情已经改变,的
不是有效的preFIX恐怕:(
In other words, unless something has changed since then, has
isn't a valid prefix I'm afraid :(
这有可能是部分的工具和库反正会认识到这样的性质,但它不依赖于它是一个好主意。
It's possible that some tools and libraries will recognise such properties anyway, but it's not a good idea to rely on it.
这篇关于布尔getter方法有效的JavaBean名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!