性能Boolean.ValueOf vs new Boolean(request.getParameter(" value"))

时间:2013-01-02 15:40:22

标签: java

  

可能重复:
  Best performance for string to boolean conversion

这被认为是更好的做法,更重要的是会让我有更好的表现吗?

1 个答案:

答案 0 :(得分:10)

布尔构造函数的文档说:

 * <p><b>Note: It is rarely appropriate to use this constructor.
 * Unless a <i>new</i> instance is required, the static factory
 * {@link #valueOf(boolean)} is generally a better choice. It is
 * likely to yield significantly better space and time performance.</b>

valueOf返回对常量值的引用,以便不创建新对象。