Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
The rules for unboxing conversions in assignments (5.2) and various other contexts (invocation, 5.3; casting, 5.5; numeric, 5.6) assert that an unboxing may be followed by a widening primitive conversion, but do not allow a widening reference conversion before the unboxing occurs. Despite these rules, longstanding behavior of javac is to allow, e.g., type variables to be widened to a boxed primitive type. <T extends Integer> void test(T arg) { int i = arg; int i2 = (int) arg; double d = arg + 1.0; Double d2 = Double.valueOf(arg); double d3 = (double) arg; } This behavior is especially important for interoperability with capture: various existing programs expect to be able to treat the elements of a 'List<? extends Integer>' as if they were ints. List<? extends Integer> li = null; int i = li.get(0); Propose to change JLS in these sections to allow a widening reference conversion before unboxing.
|