Does anyone have any tips on how to compile files that use assertions. I can't seem to get mine to work. I am using j2sdk 1.4.1_02 on an XP Home system. I am trying to use a flag: -source 1.4 nameofclass.java but it still won't compile. Any suggestions?? Thanks for any responses.
Is the compiler giving any error messages? What exactly do you mean "Won't compile"? Are you really sure a 1.4 compiler is being used? What does java -version say? [ March 30, 2003: Message edited by: Barry Gaunt ]
Here is an error message that I get when I try to compile it with TextPad: C:\source\AssertTest.java:5: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier assert i >= 0 : methodB(); ^ C:\source\AssertTest.java:5: ';' expected assert i >= 0 : methodB(); ^ C:\source\AssertTest.java:5: cannot resolve symbol symbol : class assert location: class AssertTest assert i >= 0 : methodB(); ^ C:\source\AssertTest.java:5: i is already defined in methodA(int) assert i >= 0 : methodB();
It sounds like the -source 1.4 flag isn't being recognized. Since you're using TextPad, I'm guessing the problem may be that TextPad isn't configured correctly (the compile you get by default with control-1 does not have the -source 1.4, unless you reconvifure.) Try going to Configure -> Preferences -> Tools -> Compile Java. Under "Parameters" replace "$File" with "-source 1.4 $File". Hit OK and try again to compile. If it works, you will also need to reconfigure "Run Java" with the -ea option (enable assertions) before you can run with assertions enabled.