Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 124

Given:

Which option fails?

    Correct Answer: C

    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.

Discussion
Tarik2190Option: C

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); } }

pul26Option: C

Answer is C tested

Svetleto13Option: C

C,tested

steefaandOption: C

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.

WilsonKKerllOption: C

Answer is C.