Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ScKaSx

macrumors regular
Original poster
Feb 27, 2006
105
0
I am trying to compile an example for java from THE REALLY BIG INDEX:
http://java.sun.com/docs/books/tutorial/java/javaOO/examples/Card.java

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.

Cheers,
ScKaSx
 

therevolution

macrumors 6502
May 12, 2003
468
0
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:
Code:
java -ea Card

More info on assert here.
 

aLoC

macrumors 6502a
Nov 10, 2006
726
0
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.
 

ScKaSx

macrumors regular
Original poster
Feb 27, 2006
105
0
Thanks -source 1.4 works!

Hey Guys,

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

Cheers,
ScKaSx
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.