• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic