【发布时间】:2015-05-06 21:20:20
【问题描述】:
升级到 Java 8 后。我现在遇到以下类型的编译错误:
The method with(Matcher<Object>) is ambiguous for the type new Expectations(){}
是这个方法调用引起的:
import org.jmock.Expectations;
public class Ambiguous {
public static void main(String[] args) {
Expectations expectations = new Expectations();
expectations.with(org.hamcrest.Matchers.instanceOf(Integer.class));
}
}
似乎从 instanceOf() 返回的 with 与 with() 的预期模棱两可,反之亦然。有没有办法解决这个问题?
【问题讨论】:
-
确切的 JDK 版本? JMock 版本?一个完整的源代码示例会很有帮助。
-
或许你可以给
instanceof添加类型:expectations.with(org.hamcrest.Matchers.<Integer>instanceOf(Integer.class))。
标签: generics migration java-8 hamcrest jmock