File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B "assert " explanation

 
Simon Cockayne
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What compiler version are you running? That used to work in older 1.4 compilers, but I haven't used it for a while.
 
Simon Cockayne
Ranch Hand
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 214
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic