JLS §5.2 of Java SE 11 contains some new type conversion cases which JLS of Java 8 doesn't have, see item 4 and item 5 in the list:
Assignment contexts allow the use of one of the following:
- an identity conversion
- a widening primitive conversion
- a widening reference conversion
- a widening reference conversion followed by an unboxing conversion
- a widening reference conversion followed by an unboxing conversion, then followed by a widening primitive conversion
- a boxing conversion
- a boxing conversion followed by a widening reference conversion
- an unboxing conversion
- an unboxing conversion followed by a widening primitive conversion
I don't understand the case 4 and case 5 in the list. Could anyone give me some explanation with examples? If possible, please also explain its practical usage.
Update:
As @Naman commented, here is the proposal to change the JLS - JDK-8166326 : 5.2: Allow widening before unboxing which was in effect since Java-9. In the report, it mentioned:
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);
This may imply that this JLS change do have a practical necessary. But I still don't understand why <? extends Integer> is important. What does interoperability with capture mean and why is it important? What do these various existing programs look like? Are they java code (I know some other languages also work on JVM and may have interaction with Java code)?