-
Bug
-
Resolution: Fixed
-
P4
-
None
-
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>
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>