eclipse - 为什么在 IDEA 而不是 Eclipse 中 Hamcrest 的 AllOf() 可以?
问题描述
以下测试代码在IDEA中可以编译成功,而在Eclipse中无法编译。来自 Eclipse 的消息是:
Matchers 类型中的方法 allOf(Matcher<? super T>, Matcher<? super T>) 不适用于参数 (Matcher<Object[]>, Matcher<Double[]>)。
我认为 allOf() 的第一个参数的类型推断为 Matcher<Object>,而第二个参数的类型推断为 Matcher<Double>。但是 allOf() 要求两个参数相同。如果是这样,为什么 Eclipse 会以这种方式进行推理?
public class HamTest {
@Test
public void test() {
Double s[] = { 23.0, 65.0 };
assertThat(s, allOf(arrayWithSize(2), arrayContaining(lessThan(25.0), greaterThan(30.0))));
}
}
解决方案
我知道了。我认为 ECJ 编译器错误地将 Matcher<E[]> 实例化为 Matcher<Object[]> 而不是 Matcher<Double[]> 用于 arrayWithSize()。于是修改了arrayWithSize()的调用,编译成功。
Matchers.<Double>arrayWithSize(2)
推荐阅读
- django - 如何连接登录模型和帖子模型
- python - 如何使用 Python 从 BoltDB 中读取数据?
- python - 如何在 Python 中录制系统音频?(Linux)
- scikit-learn - 初学者问题:在回归模型中变换目标的效果
- sql - MERGE TABLES 中的转换失败
- module - 这是在 Lua 中制作模块的正确方法吗?
- python - 无法正确初始化类
- android - 当我在 android 清单文件中设置活动时,如何修复“未找到默认活动”?
- hive - 如何在 HiveQL 脚本中使表名动态化?
- prolog - Prolog 输出在 True 后给出 False