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

javac fails to reject dominated pattern with the same erased type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • repo-amber
    • None
    • tools
    • generic
    • generic

      This program should not compile, but does:

      import java.util.ArrayList;

      public class X {
          public static void main(String [] args) {
              Object o = new ArrayList<X>();
      // if (o instanceof ArrayList<Integer>) { // illegal generic type for instanceof
      // System.out.println("Blah");
      // }
              if (o __matches ArrayList<Integer> ai) {
                  System.out.println("Blah");
              }
              switch (o) {
                  case ArrayList<Integer> ai:
                      System.out.println("ArrayList<Integer>");
                      break;
                  case ArrayList<String> as:
                      System.out.println("ArrayList<String>");
                      break;
              }
          }
      }

      and prints:

      Blah
      ArrayList<Integer>

            sadayapalam Srikanth Adayapalam (Inactive)
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: