I am very new in Java. I dont get the idea of this <T extends Comparable<T>>
. I mean why a T
before extends? Is that not enough to write extends Comparable<T>
? Why extends
and not implements
in javadoc its an interface, right? As I understand Comparable
compares two objects?
public class TopNPrinter<T extends Comparable<T>> {
private int N;
private String header;
public TopNPrinter(int N, String header) {
this.N = N;
this.header = header;
}
private List<T> getTopN(List<T> list) {
List<T> copy = new ArrayList<>(list);
Collections.sort(copy);
return copy.subList(0, N);
}