Reputation: 1479
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?
Upvotes: 2
Views: 1547
Reputation: 1479
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.
Upvotes: 1
Reputation: 168
in Eclipse, Right click on Project -> properties -> select java compiler-> click on java build path-> select jre ->click on edit-> Execution Environment select J2SE-1.5(jre1.8.0_65) -> finish
Upvotes: -1
Reputation: 124285
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.
Upvotes: 1