Type a generic method with a Comparable upper bound
Type a generic method with a Comparable upper bound
Answer
public static <T extends Comparable<T>> T max(List<T> xs) { return xs.stream().max(Comparator.naturalOrder()).orElseThrow(); }
<T extends Comparable<T>> means T must implement Comparable<T>. The bound unlocks compareTo and lets us express ordering constraints.