【发布时间】:2015-05-11 12:42:25
【问题描述】:
当我尝试使用 jbehave 结果表对匹配器进行 hamcrest 匹配时,我在构建 maven 时遇到编译时错误。
“错误:OutcomesTable 类中的方法 addOutcome 不能应用于给定类型”
请参考下面的示例代码。
public static <T> void method(T expected, T actual) {
OutcomesTable outcomes = new OutcomesTable();
List expectedList = (ArrayList)expected;
List actualList = (ArrayList)actual;
for(Object ExpObj : expectedList){
outcomes.addOutcome("a success", actualList, containsInAnyOrder(ExpObj));
}
outcomes.verify();
}
请指出我在这里做错了什么。
【问题讨论】:
-
这是“addOutcome”函数的类型错误。检查它的参数类型是否正确。
-
查看文档,第三个参数应该是
org.hamcrest.Matcher<List>...仔细检查您的containsInAnyOrder调用,我认为它的参数类型是罪魁祸首... -
感谢 Minits97 的支持