instanceof with generic collection

java

Solution

The correct answer is the one that you marked `ans`. You will be able to tell that `mangoList` is a `List`, but you wouldn't be able to get the type of its erased argument. The remaning choices do not make sense.

Problem

Why would the following snippet not compile ? ``` if (mangoList instanceof List<Mango>) { System.out.println("true"); } ``` - You don't know that mangoList is a List type. - The instanceof keyword only works on primitive types. - You can only check the type of collections using reflection. - Generic types are erased before runtime.(ans) - The statement could cause mangoList to be set to an instance of a List. Which do you think is the correct answer ?

Original source