Why Double::compareTo can be used as an argument of Stream.max(Comparator<? super T> comparator)
问题 The api for Stream.max requires an argument of type Comparator<? super T> , and for Comparator , the only abstract method is int compare(T o1, T o2) but Double::compareTo , the compareTo api is public int compareTo(Double anotherDouble) why just provide one argument, so why can Double::compareTo use as argument of Stream Optional<T> max(Comparator<? super T> comparator) 回答1: The below MyComparator implement a Comparator . It takes two arguments. It's the same as the lambda expression (d1,d2)