JAVA LANGUAGE Select only one answer. The correct signature for a function that
ID: 3937178 • Letter: J
Question
JAVA LANGUAGE
Select only one answer.
The correct signature for a function that sorts a list of objects using a comparator is
public static <E> void sort(List<E> list, Comparator<? super E> comp)
What is the role of the wildcard ?
a) "Comparator<? super E> comp" accepts any comparator class as long as it takes class E or its descendants as parameters to the compare() function.
b) "Comparator<? super E> comp" requires that the comparator class was defined for class E or its descendant class used as list element
c) "Comparator<? super E> comp" requires that the comparator class was defined for the superclass of class E
d) "Comparator<? super E> comp" requires that the comparator class was defined for class E or one of its ancestors
Explanation / Answer
"Comparator<? super E> comp" requires that the comparator class was defined for the superclass of class E.
By definition of comparator fucntion option c is correct.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.