This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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.
reply
    Bookmark Topic Watch Topic
  • New Topic