• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question w.r.t Assertions

 
Jeff Hu
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my understanding by reading K&B book, I can compile with code that uses "assert" as an identifier, if I use "javac -source 1.3 ..."

But when I actually compile code, I still got
==============================================
javac -source 1.3 Assert.java
Assert.java:7: warning: as of release 1.4, assert is a keyword, and may not be u
sed as an identifier
int assert = 10;
^
1 warning

Does anyone can explain it in more detail? Thanks in advance!
 
ankur rathi
Ranch Hand
Posts: 3830
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So whats the big deal .
You are just getting warning . I am sure , you are able to execute program . It is just for safety purpose .
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that the first edition of K&B's book? In SDK 1.4, assert was not a keyword unless you compiled using -source 1.4. That is, -source 1.3 was effectively the default. Now under JDK 5.0, by default you get all the features of 5.0 unless you compile with -source 1.4 or -source 1.3. So now, 1.5 is the default. That means that using JDK 5.0, you can't use assert as an identifier unless you specify -source 1.3.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic