In java8, what does the logical and & symbol mean when used on interface classes?
ringa_lee
ringa_lee 2017-05-17 09:58:41
0
1
596

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? ?

ringa_lee
ringa_lee

ringa_lee

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!