通用断言(ArrayList,hasItems(InstanceOfSomeInterface))不起作用

der*_*itz 5 java generics junit hamcrest

我想使用Hamcrest的hasItems与"实际"的集合,是一个ArrayList<? extends SomeInterface>

assertThat(ArrayList<? extends SomeInterface>, hasItems(InstanceOfSomeInterface))
Run Code Online (Sandbox Code Playgroud)

编译器说:

assertThat(T, Matcher<T>)类型中的方法Assert不适用于参数(ArrayList<capture#9-of ? extends MyInterface>, Matcher<Iterable<MyInterface>>)

出了什么问题?我该怎么办(我真的想在这里使用Hamcrest)?

Joh*_*n B 4

ArrayList<SomeInterface> newList = new ArrayList<SomeInterface>();
newList.addAll(origList);
assertThat(newList, hasItems(InstanceOfSomeInterface));
Run Code Online (Sandbox Code Playgroud)

不幸的是,Assert.assertThat 没有使用?进行编码。超级还是?扩展以允许您所描述的内容。