• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

K&B "assert " explanation

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic