Given:
public 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 K getKey () (return key;)
public V getValue () (return value;)
}
Which option fails?
A.
Foo<String, Integer> mark = new Foo<String, Integer> (“Steve”, 100););
B.
Foo<String, String> pair = Foo.<String>twice (“Hello World!”);
C.
Foo<?, ?> percentage = new Foo <> (97, 32););
D.
Foo<String, String> grade = new Foo <> (“John”, “A”);
All the options seem to be ok.
Both A and C have typos (with brackets), but that should not be related to the question.
C
do not .add()
C
sorry A. is correct answer.
anyone fails, if i remove the last ); in option A and C
mark.getKey() Steve
mark.getValue() 100
pair.getKey() Hello World!
pair.getValue() Hello World!
percentage.getKey() 97
percentage.getValue() 32
grade.getKey() John
grade.getValue() A
Something is missing. No one is failing.
A correct answer as redundant use warning.