这被认为是更好的做法,更重要的是会让我有更好的表现吗?
答案 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
返回对常量值的引用,以便不创建新对象。