你能解释一下" isXxx"在Java方法的名字呢? [英] Can you explain the "isXxx" method names in Java?
问题描述
有没有在规范中,与开始的方法的任何引用就是之一,而该方法的名称的后缀是属性的名称(类似于吸气剂的Java bean的/ setter方法)?
Is there in one of the specifications any reference to methods that start with "is", while the suffix of the method's name is a property's name (similar to getter/setter methods of Java beans)?
例如:
public boolean isConditionTrue() {
...
...
}
private boolean conditionTrue;
谢谢!
推荐答案
仅适用于原始的布尔值。下面是从规范:
is only valid for primitive boolean. Here is an excerpt from the spec:
8.3.2布尔属性
此外,对于布尔属性,我们允许一个getter方法匹配的模式:
公共布尔是();
这个是可以被提供,而不是一个获取甲方法
外径,或者可以除了一个获取方法提供的。
在这两种情况下,如果是的方法是一个布尔属性present那么我们将
用是的方法来读取属性值。
一个例子布尔属性可能是:
公共布尔isMarsupial();
公共无效setMarsupial(布尔米);
8.3.2 Boolean properties In addition, for boolean properties, we allow a getter method to match the pattern: public boolean is(); This "is" method may be provided instead of a "get" meth- od, or it may be provided in addition to a "get" method. In either case, if the "is" method is present for a boolean property then we will use the "is" method to read the property value. An example boolean property might be: public boolean isMarsupial(); public void setMarsupial(boolean m);
注意使用 isXxx()的:布尔
的功能,如果你要会同像JSTL标记物(使用 $ {使用它们object.xxx}
语法)。他们不会把它捡起来,你必须修改它的getXxx():布尔
Be aware of using isXxx() : Boolean
functions if you are going to use them in conjunction with things like JSTL tags (using ${object.xxx}
syntax). They won't pick it up and you have to modify it to getXxx() : Boolean
.
这篇关于你能解释一下" isXxx"在Java方法的名字呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!