Why does List<Object> y = new ArrayList<String>(); fail to compile in Java?
-
-
-
-
Correct answer B. Generic types are invariant in their type argument
Explanation
Although String is a subtype of Object, List is not a subtype of List
Answer checked · How we write and check questions
Tip: press A, B, C or D to answer, and N for the next question.
Advertisement
Discussion