设计图书馆时何时使用 PECS?

When to use PECS when designing a library?

我正在开发一个大量使用函数接口的库,目前正在纠结是否应用 PECS

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>

这太难读了。我已经阅读了 但仍然纠结是否应用它,因为它会污染库代码并使编译器错误消息恶化。就我个人而言,我会为 Predicate<A> 变体选择 PCES。

有没有应用PECS的指南?我知道利弊,但我想知道人们真正存储的频率是多少。 Predicate 作为 lamda 和方法引用的字段不受 PECS 提供的影响。我没有在网上找到任何进一步的建议。 Here 是受此影响的 类 之一。

正如在下面的评论中广泛讨论的那样,post:与 JDK/标准库的一致性和一致性及其对 PECS 的使用以及通过使用 PECS 获得的兼容性改进是一个很好的论据始终使用 PECS(至少在设计库时)