-
Bug
-
Resolution: Fixed
-
P4
-
8
The start of 5.5 lists various conversions that are allowed in a casting context.
"Casting contexts allow the use of one of:
• an identity conversion (§5.1.1)
• a widening primitive conversion (§5.1.2)
• a narrowing primitive conversion (§5.1.3)
• a widening and narrowing primitive conversion (§5.1.4)
• a widening reference conversion (§5.1.5) optionally followed by either an unboxing conversion (§5.1.8) or an unchecked conversion (§5.1.9)
• a narrowing reference conversion (§5.1.6) optionally followed by either an unboxing conversion (§5.1.8) or an unchecked conversion (§5.1.9)
• a boxing conversion (§5.1.7) optionally followed by a widening reference conversion (§5.1.5)
• an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion (§5.1.2)."
This list has various problems:
- It doesn't include all allowed reference type casts (per 5.5.1), such as from Runnable to Cloneable
- It doesn't allow widening before unboxing followed by primitive widening, even though javac does (seeJDK-8166326)
- The use of "widening and narrowing primitive conversion" adds unnecessary complexity, since we could just as easily describe this as "a widening primitive conversion followed by a narrowing primitive conversion". (Cleaning this up means deleting 5.1.4, though, a disruption that may not be worth it.)
- It gives the impression that any listed conversion is allowed, even though some unchecked conversions are not (per 5.5.1)
- It is redundant, since the next paragraph restates it more precisely.
Propose rewriting to merge with the subsequent description and to accurately reflect the set of legal conversions.
"Casting contexts allow the use of one of:
• an identity conversion (§5.1.1)
• a widening primitive conversion (§5.1.2)
• a narrowing primitive conversion (§5.1.3)
• a widening and narrowing primitive conversion (§5.1.4)
• a widening reference conversion (§5.1.5) optionally followed by either an unboxing conversion (§5.1.8) or an unchecked conversion (§5.1.9)
• a narrowing reference conversion (§5.1.6) optionally followed by either an unboxing conversion (§5.1.8) or an unchecked conversion (§5.1.9)
• a boxing conversion (§5.1.7) optionally followed by a widening reference conversion (§5.1.5)
• an unboxing conversion (§5.1.8) optionally followed by a widening primitive conversion (§5.1.2)."
This list has various problems:
- It doesn't include all allowed reference type casts (per 5.5.1), such as from Runnable to Cloneable
- It doesn't allow widening before unboxing followed by primitive widening, even though javac does (see
- The use of "widening and narrowing primitive conversion" adds unnecessary complexity, since we could just as easily describe this as "a widening primitive conversion followed by a narrowing primitive conversion". (Cleaning this up means deleting 5.1.4, though, a disruption that may not be worth it.)
- It gives the impression that any listed conversion is allowed, even though some unchecked conversions are not (per 5.5.1)
- It is redundant, since the next paragraph restates it more precisely.
Propose rewriting to merge with the subsequent description and to accurately reflect the set of legal conversions.
- relates to
-
JDK-4770188 byte to char a narrowing conversion?
-
- Closed
-
-
JDK-6558543 Widening reference conversion followed by unboxing isn't allowed
-
- Closed
-
-
JDK-8166326 5.2: Allow widening before unboxing
-
- Closed
-
-
JDK-8168269 Javac compile error on cast to primitive when using generics wirldcards
-
- Closed
-