On 10/9/15 4:16 AM, Aleksey Shipilev wrote:
Please note that "static final Boolean myBool = new Boolean(true).booleanValue()" is a spec-recommended way to avoid binary incompatibilities caused by conditional compilation. See JLS 13.4.9. Therefore, deprecating Boolean constructors is a spec issue as well.
Well, not "recommended" :-) but point well taken. From JLS 13.4.9:
We note, but do not recommend, that if a field of primitive type of an interface may change, its value may be expressed idiomatically as in: boolean debug = new Boolean(true).booleanValue();
The bit about conditional compilation is with regard to constant expressions. The goal here is to get a boolean value into the initializer of a field, but to have that initializer not be a constant expression. I think that
Boolean.valueOf(true).booleanValue() would be sufficient for this and avoids using the constructor. I'll file a bug on the JLS for this. Thanks! s'marks