I am looking at the source code of the Comparator.comparing
method implemented in Java8
here is the code
public static <T, U> Comparator<T> comparing(
Function<? super T, ? extends U> keyExtractor,
Comparator<? super U> keyComparator)
{
Objects.requireNonNull(keyExtractor);
Objects.requireNonNull(keyComparator);
return (Comparator<T> & Serializable)
(c1, c2) -> keyComparator.compare(keyExtractor.apply(c1),
keyExtractor.apply(c2));
}
Why the bit-wise and
between Comparator
and Serializable
is required and what it does?
(Comparator<T> & Serializable)
It can be simply casted to Comparator
for chaining.
also how does bit-wise operations works in case of non numeric values?
Thanks.