我正在开发一个库,该库大量使用功能接口,目前还在努力是否应用果胶:
Predicate<A>
Function<A,B>
BiFunction<A,B,C>与
Predicate<? super A>
Function<? super A, ? extends B>
BiFunction<? super A,? super B,? extends C>它看起来太混乱了,甚至错误信息也来自:
Incompatible types: Function<Item, Long> is not convertible to Function<Item, String>到某种程度上
Incompatible types:
Function<capture of ? super Item, capture of ? extends Long> is not
convertible to Function<capture of ? super Item, capture of ? extends String>很难读懂。我已经阅读了以下问题,但仍然难以确定是否要应用它,因为它污染了库代码并恶化了编译器错误消息。就我个人而言,我会选择PCES作为Predicate<A>变体。
是否要使用果胶,是否有指引呢?我知道优点和缺点,但我想知道人们是否经常将Predicate存储在字段中,因为lamdas和方法引用不受PECS提供的内容的影响。我没有在网上找到任何进一步的建议。这里是受此影响的类之一。
发布于 2019-05-26 22:25:21
正如下面的评论中所广泛讨论的:与JDK /标准库的一致性和对齐性,以及它对PECS的使用与通过使用PECS所获得的可压缩性的改善是一个很好的论据,可以始终使用PECS (至少在设计库时)。
https://stackoverflow.com/questions/56316502
复制相似问题