本文主要是介绍java8中,逻辑与 符号用在接口类上代表什么意思,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近在读lambda表达式相关的java源码,在Comparator的静态方法里发现有不少这种类似的写法
java.util.Comparator
…
public static Comparator comparingInt(ToIntFunction<? super T> keyExtractor) {
Objects.requireNonNull(keyExtractor);
return (Comparator & Serializable)
(c1, c2) -> Integer.compare(keyExtractor.applyAsInt(c1), keyExtractor.applyAsInt(c2));
}
其中return (Comparator & Serializable)应该是表示类型强转
The part I’m interested in is this: return (Comparator & Serializable):
This means that the resulting value will be cast to Comparator and Serializable (i.e. a serializable comparator)
Note that when doing casts like this one, you’re allowed to specify only one class (and infinite amount of interfaces), because it’s not possible for a class to inherit from more than one super-class.
这篇关于java8中,逻辑与 符号用在接口类上代表什么意思的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!