[Java Spec Report] casts and unboxing
Thomas Graf <[email protected]> Wed, 08 Sep 2004 21:55:54 +0200
| Newsgroups | gmane.comp.java.spec-report |
|---|---|
| Message-ID | <[email protected]> |
The following program is compiled without error by Javac 1.5.0-rc:
public class Cast {
public static void main(String[] args) {
Integer oi = 2;
double pd = 3;
pd = (double)oi;
}
}
According to the JLS 3 draft distributed with the documentation for
JSR-014, §5.5, casting conversion is applied to the operand of a cast
operator (§15.16): the type of the operand expression must be converted
to the type explicitly named by the cast operator. Casting contexts
allow the use of an identity conversion (§5.1.1), a widening primitive
conversion (§5.1.2), a narrowing primitive conversion (§5.1.3), a
widening reference conversion (§5.1.5),
a narrowing reference conversion (§5.1.6), a boxing conversion (§5.1.7)
or an unboxing conversion (§5.1.8).
In order to convert an expression of class and type Integer to primitive
type double, unboxing conversion followed by widening primitive
conversion must be applied.
Please note that the assignment without the cast is valid, because the
assignment conversions allows the unboxing conversion to be followed by
a widening primitive conversion.
I am confused.
Thomas
------------------------ Yahoo! Groups Sponsor --------------------~-->
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/5cFolB/TM
--------------------------------------------------------------------~->
To unsubscribe from this mailing list, send an email to:
[email protected]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/java-spec-report/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/