JDK-6588248 : narrowing primitive conversion after unboxing conversion should work
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-08-02
  • Updated: 2010-04-04
  • Resolved: 2008-01-30
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
Reopen 4995668 as a request for enhancement
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4995668

JUSTIFICATION :
It is very difficult to understand the current specification of autoboxing/unboxing. Because narrowing primitive conversion after unboxing conversion and widening primitive conversion before boxing conversion doesn't work well. It needs an extra cast.

Although
int i1 = (int)2L;
can be compile,
int i2 = (int)Long.valueOf(2L);
         ^^^^^
can not be compiled. Now,
int i3 = (int)(long)Long.valueOf(2L);
              ^^^^^^
can be compile.

Although
float f1 = 2;
can be compile,
Float f2 = 2;
can not be compiled. Now,
Float f3 = (float)2;
           ^^^^^^^
can be compile.

P.S. Although
long l1 = 2;
can be compile,
Long l2 = Integer.valueOf(2);
can not be compiled. Now,
Long l3 = (long)Integer.valueOf(2);
          ^^^^^^
can be compile. I want to write
Long l2 = Integer.valueOf(2);