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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 5.0
    • 5.0
    • tools
    • generic
    • generic

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: