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 名称
基础教程推荐
- JPA惰性列表上的流 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
