类型列表的 AssertJ 条件的泛型问题

Generics issue with AssertJ Condition for a typed List

在 Java 上探索 AssertJ 3.5.2 中 Condition class 的使用时,我 运行 陷入了这个问题 8. 我可以为一般类型的 List 创建一个 Condition 实例,但是当我尝试使用它时,我在 Eclipse 中收到错误消息:

Condition<List<MyBean>> listCond =
        new Condition<>(list -> true, "test"); // OK

this.assertThat(myList).has(listCond); // DOES NOT COMPILE

我收到的错误消息是:

The method has(Condition<? super List<? extends MyBean>>) in the type 
AbstractListAssert<capture#8-of ?,List<? extends MyBean>,MyBean,ObjectAssert<MyBean>> is not 
applicable for the arguments (Condition<List<MyBean>>)

AssertJ 中的这种或另一种方法是否有解决方案来对列表进行整体检查(不仅仅是逐项检查,而是基于序列或聚合的检查)?

我相信像这样声明你的条件应该可以解决编译错误:

Condition<? super List<? extends MyBean>> listCond = new Condition<>(list -> true, "test");