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

Type inference broken with Interfaces

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
          public static <T extends List> T newList() {
              return null;
          }

          public static void main(String[] args) {
              String s = newList();
          }
      following code works fine while it should not compile.

               0: invokestatic #4 // Method newList:()Ljava/util/List;
               3: checkcast #5 // class java/lang/String
       the type is inferred correctly but the assignment of a List to String is permitted.

      Only happens to interfaces. changing to a concrete class no longer compiles.

      REGRESSION. Last worked in version 6u45


      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: