View Full Version : java assertion compiling error

Apr 9, 2007, 08:32 PM
I am trying to compile an example for java from THE REALLY BIG INDEX:

However whenever I try to compile:
javac Card.java
I get the following error:
"warning: as of release 1.4, assert is a keyword, and may not be used as an identifier"

And if I try to compile it with enable assertions I get:
javac: invalid flag: -ea
Usage: javac <options> <source files>

Any ideas on how to get this code to compile? I am running Java version 1.4.2_12, which I believe should be able to handle assertions. Thanks for your help.


Apr 9, 2007, 10:58 PM
Warning messages aren't fatal. If that's all you saw, then the compile was probably successful. Do you see a Card.class in that directory? If so, then you don't need to do anything about the warning.

Also, while I didn't actually try this (nor have I ever used assertions in Java), it looks like you add the '-ea' flag when running your program, not when compiling it. Like this:

java -ea Card

More info on assert here. (http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html)

Apr 10, 2007, 09:49 AM
From memory, I think it's something like
javac -source 1.4

Then it will understand the asserts as being asserts and not a variable named assert.

Apr 10, 2007, 03:14 PM
Hey Guys,

Thanks for the response. What worked for me was aloc's suggestion to compile with the flag -source 1.4. Thanks again.