javac fails to reject dominated pattern with the same erased type

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • repo-amber
    • Affects Version/s: None
    • Component/s: 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>

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

              Created:
              Updated:
              Resolved: