Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6588248

narrowing primitive conversion after unboxing conversion should work

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • specification
    • x86
    • windows_xp

      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);

            abuckley Alex Buckley
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: