assertNotEquals静态导入导致编译出错 [英] assertNotEquals static import causing compile error

查看:890
本文介绍了assertNotEquals静态导入导致编译出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件 Foo.java 这没有错误编译。但是,当我添加了一行

I have a file Foo.java which compiles with no errors. But when I add the single line

import static org.junit.Assert.assertNotEquals;

这导致以下错误从我的Ant构建:

This causes the following error from my ant build:

compileTests:
[javac] Compiling 27 source files to C:\example\bin
[javac] C:\example\src\Foo.java:7: error: cannot find symbol
[javac] import static org.junit.Assert.assertNotEquals;
[javac] ^
[javac]   symbol:   static assertNotEquals
[javac]   location: class
[javac] 1 error

我使用JUnit 4.4。 的junit-4.4.jar 包含在的classpath 的javac 任务。

我曾尝试与标志运行不同的编译器版本<​​code> -Dbuild.compiler = javac1.7 和 -Dbuild.compiler = javac1.8 ,但它并没有区别。我仍然得到确切的同样的错误。

I have tried running different compiler versions with the flags -Dbuild.compiler=javac1.7 and -Dbuild.compiler=javac1.8 but it makes no difference. I still get the exact same error.

assertNotEquals 是断言只有静态导入导致此错误。

assertNotEquals is the only static import from Assert that causes this error.

我已经看到了这个帖子<一个href=\"http://stackoverflow.com/questions/17835780/java-static-import-causing-compile-error-probable-compiler-bug\">Java静态导入引起编译错误。可能的编译器错误?
我试图导入断言自身和prepending每个断言与断言语句。喜欢这个职位建议。我得到了同样的错误,这一次的方法调用 Assert.assertNotEquals()而不是import语句。

I have already seen this post Java static import causing compile error. Probable compiler bug? and I tried importing Assert on its own and prepending each assert statement with Assert. like this post suggested. I got the same error, this time at the method call for Assert.assertNotEquals()instead of the import statement.

导入成功编译和运行Eclipse的,但是。

The import successfully compiles and runs on Eclipse, however.

有没有人对这个原因的任何想法?我希望去的这条底线,而不必实施一种变通方法解决方案。

Does anyone have any ideas about the cause of this? I'd like to get to the bottom of this instead of having to implement a workaround solution.

推荐答案

正在使用JUnit 4.4。 AssertNotEquals 未添加至4.11

You are using Junit 4.4. AssertNotEquals wasn't added until 4.11

的JUnit 4.11发行说明

如果您更新到最新的JUnit罐子。编译错误应该消失。 Eclipse是可能使用它自己的内置版本具有最新的方法。

If you update to the latest JUnit jar. the compiler error should go away. Eclipse is probably using its own built in version that has the latest methods.

这篇关于assertNotEquals静态导入导致编译出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆