Given:
Which option fails?
Given:
Which option fails?
The correct answer is that the code in option A will fail. The reason is that it attempts to assign an object of type Foo<Object, Object> to a variable of type Foo<String, Integer>. In Java, generic types are invariant, meaning that Foo<Object, Object> is not a subtype of Foo<String, Integer>, even if String and Integer are subtypes of Object. This results in a type mismatch error.
Answer A. Tested Type mismatch: cannot convert from Foo<Object,Object> to Foo<String,Integer>
A is correct. Can't have different types on left and right side if not using super/extends on left side.
Answer is A. <Object, Object> cannot cast to <String, Integer>
Answer is A. Tested.
A,tested