Community
Participate
Working Groups
Explicit constructor calls upon primitive types wrappers (Boolean, Byte, Character, Short, Integer, Long, Float and Double) have significant drawbacks compared to the use of a factory method (such as Boolean.valueOf()) or a boxing conversion (in 5.0 mode). Especially, the valueOf reference documentation insists that it is expected to have better space and time behavior than the constructor, and JLS 5.1.7 requires that some values be treated as singletons by conforming implementations (true, false, bytes, chars between \u0000 and \u007f inclusive, ints and shorts between -128 and 127 inclusive). Their use could raise a specific warning (note that boxing conversions already raise a warning as of 3.2 M2). In support for this, the following code: class X { public static void main(String args[]) { Integer i1 = new Integer(0), i2 = (Integer) 0, i3 = Integer.valueOf(0); if (i1 == i2) { System.out.println("i1 == i2"); } if (i1 == i3) { System.out.println("i1 == i3"); } if (i3 == i2) { System.out.println("i2 == i3"); } } } (only) displays: i2 == i3