Recently I was reading the java source code related to lambda expressions, and found a lot of similar writing methods in the static methods of Comparator
java.util.Comparator
...
public static <T> Comparator<T> comparingInt(ToIntFunction<? super T> keyExtractor) {
Objects.requireNonNull(keyExtractor);
return (Comparator<T> & Serializable)
(c1, c2) -> Integer.compare(keyExtractor.applyAsInt(c1), keyExtractor.applyAsInt(c2));
}
Among them, return (Comparator<T> & Serializable)
should represent type forced conversion, but why not convert it directly to Comparator<T>
instead of using the logical AND symbol? ?
phpcn_u15822017-05-17 10:00:41
This means forced conversion to Comparator<T>
和Serializable
You can read this explanation