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)?
ArrayList<SomeInterface> newList = new ArrayList<SomeInterface>();
newList.addAll(origList);
assertThat(newList, hasItems(InstanceOfSomeInterface));
Run Code Online (Sandbox Code Playgroud)
不幸的是,Assert.assertThat 没有使用?进行编码。超级还是?扩展以允许您所描述的内容。