Skip to main content

Practice ยท 1 of 3

Prove erasure to yourself

1. static boolean sameErasure() โ€” true iff new ArrayList<String>().getClass() is the SAME object as new ArrayList<Integer>().getClass() (==). 2. static boolean arraysReified() โ€” true iff String[].class != Integer[].class. 3. static String classOfAList() โ€” return new ArrayList<String>().getClass().getName(). 4. static String arrayStore() โ€” inside the method: Object[] objs = new String[1]; then attempt objs[0] = 42; catching the runtime failure; return exactly "ArrayStoreException" (arrays enforce element type at runtime).

Difficulty: advanced

Back to lesson: Practice: Type-system drills