Java 使用Hamcrest everyItem()的编译错误

Java 使用Hamcrest everyItem()的编译错误,java,generics,junit,hamcrest,Java,Generics,Junit,Hamcrest,我试图在Hamcrest中的everyItem()上使用hasKey(),但我得到以下编译错误: error: no suitable method found for assertThat(List<Map<String,Object>>,Matcher<Iterable<Map<? extends String,?>>>) assertThat(data, everyItem(hasKey("index")));

我试图在Hamcrest中的
everyItem()
上使用
hasKey()
,但我得到以下编译错误:

error: no suitable method found for assertThat(List<Map<String,Object>>,Matcher<Iterable<Map<? extends String,?>>>)
        assertThat(data, everyItem(hasKey("index")));
        ^
    method Assert.<T#1>assertThat(T#1,Matcher<? super T#1>) is not applicable
      (actual argument Matcher<Iterable<Map<? extends String,?>>> cannot be converted to Matcher<? super List<Map<String,Object>>> by method invocation conversion)
    method Assert.<T#2>assertThat(String,T#2,Matcher<? super T#2>) is not applicable
      (cannot instantiate from arguments because actual and formal argument lists differ in length)
  where T#1,T#2 are type-variables:
    T#1 extends Object declared in method <T#1>assertThat(T#1,Matcher<? super T#1>)
    T#2 extends Object declared in method <T#2>assertThat(String,T#2,Matcher<? super T#2>)
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

错误:找不到适合assertThat(List,Matcher>>的方法无法转换为Matcher这是嵌套泛型的情况

数据
当前被声明为
列表
,而被推断为返回一个
匹配器
,但这可能有一个很好的理由

幸运的是,您的代码非常简单,可以将
数据
声明为

List<Map<? extends String, ?>> data = new ArrayList<>();

列表请列出您的导入语句。(手头没有环境)为
数据添加强制转换是否有效?即
资产((可编辑)数据,每个项目(hasKey(“索引”))
我尝试用您的代码行替换asker测试代码的第一行。它没有为我编译。@Jazzepi在Eclipse和Java 7中对我很好。谢谢,这很有效。编译消息很清楚,我只是在找到括号和尖括号的正确组合以使其编译时遇到问题;没有考虑一下我所知道的类型。
List<Map<? extends String, ?>> data = new ArrayList<>();