The specification for assignment contexts (JLS 5.2) allows an unboxing conversion followed by a widening primitive conversion. It does _not_ allow a widening reference conversion before this occurs. But javac is permitting it.
The following is allowed:
<T extends Integer> void test(T arg) {
int i = arg; // JLS: error; javac: ok
}
But not the complementary boxing case:
void test2(int i) {
Long l = i; // JLS: error; javac: error
}
The following is allowed:
<T extends Integer> void test(T arg) {
int i = arg; // JLS: error; javac: ok
}
But not the complementary boxing case:
void test2(int i) {
Long l = i; // JLS: error; javac: error
}
- relates to
-
JDK-8166421 14.14.2: Bugs in desugaring of for-each
-
- Open
-
-
JDK-8166326 5.2: Allow widening before unboxing
-
- Closed
-
-
JDK-8030018 Lambda Spec: Inference should generate an eq bound from an unboxing constraint
-
- Closed
-
-
JDK-6526446 Fixes to JLS5.5 Casting Conversion
-
- Closed
-