• 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

Assertion

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the Assertion working like an error message in jdk1.4 ?
Would you like to give me an example how it works?
Thanks
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
assert is a keyword. It evaluates a boolean expression. if the expression is true, nothing happens. If it is false, an AssertionError is thrown at the point where the assert statement fails.
example:
assert (myVar == 1) ; //if the variable "myVar" does not contain the int value '1', then an AssertionError is thrown.
 
Author
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a second, longer form for assertions as well:
assert foo != null : "Can't get a Foo, argument="+argument;
This is roughly equivalent to:
if (!(foo != null))
throw new AssertionError(
"Can't get a Foo, argument="+argument );
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic