Given:
Which option fails?
Given:
Which option fails?
Option A is correct because it correctly specifies both the key and value types. Option B is correct because the twice method properly returns an instance where both types are the same. Option D is correct because it uses the diamond operator to correctly infer the types. Option C fails because it attempts to assign a Foo<String, Integer> object to a Foo<Object, Object> variable, which is type-incompatible. This contradicts the generic type system of Java, where the declared generic types on both sides of the assignment must match or be covariant.
Answer is C, class Foo<K,V>{ private K key; private V value; public Foo(K key, V value) { this.key = key; this.value = value; } public static <T> Foo<T,T> twice(T value) { return new Foo<T,T>(value,value); } } public class Test { public static void main (String[] args) throws InterruptedException { Foo<Object,Object> percentage = new Foo<String,Integer>("Steve",100); } }
Answer is C tested
C,tested
C is correct. You can't have Object on left side and String/Integer on right. You could have ? extends Object on left side and then it would compile.
Answer is C.