import java.util.ArrayList; import java.util.LinkedList; import java.util.List; class GenericsCasts { // Cast from a raw type to a generic type // :: warning: [unchecked] unchecked cast List[] o = (List[]) new List[] {new ArrayList()}; class Data {} // Use our own dummy method as to avoid a complaint from the Signature Checker Data forName(String p) { throw new Error(""); } void m() { // Cast from a wildcard to a normal type argument. // Warning only with -AcheckCastElementType. // TODO:: warning: (cast.unsafe) // :: warning: [unchecked] unchecked cast Data c = (Data) forName("HaHa!"); } // Casts from something with one type argument to two type arguments // are currently problematic. // TODO: try to find a problem with skipping this check. class Test { class Entry extends LinkedList {} class Queue { List poll() { throw new Error(""); } } void trouble() { Queue queue = new Queue<>(); // Warning only with -AcheckCastElementType. // TODO:: warning: (cast.unsafe) // :: warning: [unchecked] unchecked cast Entry e = (Entry) queue.poll(); } } public static int indexOf(T[] a) { return indexOfEq(a); } public static int indexOfEq(Object[] a) { return 0; } }