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

javac fails to compile valid code with "inconvertible types" Error

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: 5.0
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      SYNOPSIS
      --------
      javac fails to compile valid code with "inconvertible types" Error

      OPERATING SYSTEM
      ----------------
      All

      FULL JDK VERSION
      ----------------
      5.0, Java 6 and JDK 7

      REPRODUCTION INSTRUCTIONS
      -------------------------
      Attempt to Compile the attached testcase with javac.

      TESTCASE SOURCE
      ---------------
      import java.util.*;

      public class CollectionsExample {
          public static void main(String[] args) {
              int[] a = {1,2,3,4};
             
              // Fails
              Collection<? extends Class<?>> collection = (Collection<? extends Class<?>>) Arrays.asList(a);

              // Works
              //List list = Arrays.asList(a);
              //Collection<? extends Class<?>> collection = (Collection<? extends Class<?>>) list;
          }
      }

      WORKAROUND
      ----------
      Split the failing line over two lines, as shown in the testcase. Despite the two versions of the code being syntactically equivalent, one fails to compile while the other compiles successfully (although it does produce an "unchecked cast" warning).

        Attachments

          Activity

            People

            • Assignee:
              mcimadamore Maurizio Cimadamore
              Reporter:
              dkorbel David Korbel (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: