JAVA LANGUAGE Select only one answer The correct signature f

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

Solution

\"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.

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(

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site