• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

query regarding assertion

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm preparing for scjp 1.4

In this program

class Test
{
public static void main(String args[])
{
assert false;
}
}

i compiled using 1.4.2 JDK

D:\javatest>javac -d d:\javatest d:\javatest\package\Test.java
d:\javatest\package\Test.java:5: warning: as of release 1.4, assert is a keyword
, and may not be used as an identifier
assert false;
^
d:\javatest\package\Test.java:5: not a statement
assert false;
^
d:\javatest\package\Test.java:5: ';' expected
assert false;
^
2 errors
1 warning

BUT

D:\javatest>javac -source 1.4 -d d:\javatest d:\javatest\package\Test.java

I cant understand why assertion is not compiling when the source is not set, this was not happening for jdk 1.5
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although 1.4 and 1.5 both treat assert as a keyword, assertion is disabled for 1.4 by default while enabled for 1.5 by default when compiling. I believe K&B talks about it when it introduces assert so you can refer to it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic