I tried enabling assertions for Java 8 in Eclipse Luna by doing what most answers on here suggest, adding -ea as a VM argument in the Run config, as well as in the default VM arguments in the JRE config. Still I get the same error as before:
Multiple markers at this line - 'assert' should not be used as an identifier, since it is a reserved keyword from source level 1.4 on - Syntax error on token "assert", ( expected - Syntax error, insert "AssignmentOperator Expression" to complete Expression - Syntax error, insert ")" to complete Expression
My program is really just a simple program to try it out:
public class Test {
public static void main (String[] args) {
int x = 10;
assert x != 0 : "Test";
System.out.println(x);
}
}
What am I doing wrong?
将括号括在x!= 0周围。这可能会解决您的问题。
Go to Window
-> Preferences
-> Java
-> Installed JREs
-> select your installed JVM -> Edit..
-> in "Default VM arguments:" add -ea
.
Finally make sure that your project uses same JVM in which you added -ea
as default argument. To do that :
right click on project
-> Properties
-> JavaBuildPath
-> Libraries
here you should see JRE system library[...]
. Make sure that in [...]
is JVM you edited to enable assertions.
I thought I anwer my own question, since the solution was hidden in a comment until now:
Removing -ea from the default parameters, but keeping it in the run configuration solved the problem, for me.
在Eclipse中,右键单击Project-> properties->选择Java编译器->单击Java构建路径->选择jre->单击edit-> Execution Environment选择J2SE-1.5(jre1.8.0_65)->完成
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.