| Author |
K&B "assert " explanation
|
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Hi, K&B book - Chapter 4, page 260 says: to use assert as an indentifier use... javac -source 1.3 myclass.java ...moreover that -source 1.3 is the default, so it is the same as using... javac -source 1.3 myclass.java ...but I get an error in both cases: C:\myjava>javac assertTest.java assertTest.java:4: warning: as of release 1.4, assert is a keyword, and may not be used as an identifier int assert; What's the score? Cheers, Si.
|
SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
|
 |
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
|
|
|
What compiler version are you running? That used to work in older 1.4 compilers, but I haven't used it for a while.
|
Give a man a fish, he'll eat for one day. <br />Teach a man to fish, he'll drink all your beer.<br /> <br />Cheers,<br /> <br />Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
|
 |
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Hi Jeff, C:\myjava>java -version java version "1.4.2_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03) Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode) Cheers, Simon
|
 |
Jeff Bosch
Ranch Hand
Joined: Jul 30, 2003
Posts: 804
|
|
If you use assertions, compiling under -source 1.3 will generate a warning, but not an error. That's okay. But, assert must be used as a legal identifier, not in the format of an assertion check. Warnings don't interfere with the program running. Does that help? [ March 23, 2005: Message edited by: Jeff Bosch ]
|
 |
Simon Cockayne
Ranch Hand
Joined: Dec 09, 2000
Posts: 214
|
|
Hi Jeff, ...and the fog lifts. Jeff, thanks for pointing out that it is a warning and not an error. I think I now understand all the variations of compile and run at 1.4 and prior, with and without assert, as a keyword and as an identifier. Cheers, Simon.
|
 |
 |
|
|
subject: K&B "assert " explanation
|
|
|