What is the output of the Java code System.out.println(new ArrayList<String>().getClass() == new ArrayList<Integer>().getClass());?
Correct answer C. true
Explanation
Generic type arguments are erased during compilation, so at run time there is only one class, ArrayList, for every parameterisation. Both getClass calls return that same Class object and the comparison is true. This erasure also explains why code cannot test obj instanceof List against an arbitrary Object at run time.
Answer checked How we write and check questions
Discussion