boolean(Boolean) - getter是vs get [英] boolean (Boolean) - getter is vs get

查看:121
本文介绍了boolean(Boolean) - getter是vs get的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来每个人都说正确的getter:

It looks like everyone says that right getter for:


  • 原始布尔 - > getter

  • object Boolean - > getter get

  • primitive boolean -> getter is
  • object Boolean -> getter get

示例:

public class Test {

    private boolean primitive;
    private Boolean object;

    public boolean isPrimitive() {
         return primitive;
    }
    public Boolean getObject() {
        return object;
    }
    //..
}

问题:

是否有任何规范或文档表明这是正确的,这是为布尔值指定getter的方法?或者这只是一个常见的假设?

Is there any spec or document that states this is correct and this is the way to specify getters for boolean values? Or this is only a common assumption?

我问因为例如 wsimport 为布尔生成了getter 宾语。这是一个工具错误,或者这是允许和正确的吗?

I'm asking becouse for example wsimport generates getter is for Boolean object. Is this a tool bug, or this is allowed and correct?

另一方面,一些framweork与这样的getter不能正常工作。例如JSF(EL)或Dozer。

In the other hand some framweorks don't work properly with such getters. For example JSF (EL) or Dozer.

推荐答案

字段的getter方法 boolean myField getMyfield() isMyField()(由用户自行决定)。我个人使用第二种格式,就像许多源代码生成工具一样。

The getter method for the field boolean myField is getMyfield() or isMyField() (it's up to the user to choose). I personally use the second format, as many source code generating tools do.

这种格式是标准,它在 JavaBeans中定义规格。请参阅本文档的部分8.3.2
http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/

This format is a standard, it is defined in the JavaBeans specification. See the section 8.3.2 of this documentation: http://download.oracle.com/otndocs/jcp/7224-javabeans-1.01-fr-spec-oth-JSpec/

来自文档的引用:


In addition, for boolean properties, we allow a getter method to match the pattern:

  public boolean is<PropertyName>();


文档没有谈到像<的原始包装器code> Boolean class。

The documentation doesn't talk about the primitive wrappers like the Boolean class.

这篇关于boolean(Boolean) - getter是vs get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆