Valid JavaBeans names for boolean getter methods(布尔 getter 方法的有效 JavaBeans 名称)
问题描述
我知道大多数变量名都可以与is"一起使用,例如 isBlue(),但has"是否也是有效前缀,例如 hasProperty()?
I know most variable names will work with "is", such as isBlue(), but is "has" also a valid prefix, like hasProperty()?
推荐答案
根据JavaBeans 规范 8.3.2 节:
According to the JavaBeans specification section 8.3.2:
布尔属性
此外,对于布尔属性,我们允许一个 getter匹配模式的方法:
public boolean is
这"isPropertyName" 方法可能是提供而不是"get<PropertyName>" 方法,也可以除了提供一个get"方法.在任一情况下,如果 is 方法然后存在布尔属性我们将使用is<PropertyName>"方法来读取属性值.一个示例布尔属性可能是:
公共布尔 isMarsupial();public void setMarsupial(boolean m);
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);
换句话说,除非从那以后发生了一些变化,否则 has 恐怕不是一个有效的前缀:(
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 方法的有效 JavaBeans 名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:布尔 getter 方法的有效 JavaBeans 名称
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
