且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

你能解释一下“isXxx"吗?Java中的方法名称?

更新时间:2023-11-10 07:51:39

仅对原始布尔值有效.以下是规范的摘录:

is only valid for primitive boolean. Here is an excerpt from the spec:

8.3.2 布尔属性此外,对于布尔属性,我们允许使用 getter 方法来匹配模式:公共布尔是();可以提供这个is"方法而不是get"方法od,或者它可以作为get"方法的补充.在任何一种情况下,如果布尔属性存在is"方法,那么我们将使用is"方法读取属性值.一个示例布尔属性可能是:public boolean isMarsupial();public void setMarsupial(boolean m);

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() : Boolean 函数,如果你打算将它们与 JSTL 标签之类的东西结合使用(使用 ${object.xxx} 语法)).他们不会拿它,你必须将它修改为 getXxx() : Boolean.

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.