• 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

Assertions

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

For the above code one of the answers says the following is true
"The assert statements are being used to check a precondition--something that must be true when the method is invoked".
Is that statement always true??? In other words: is it a general statement?
In some other question the above statement is listed as not true.
Can someone explain the meaning of that statement and the relevance for the above code.
Thanks a bunch
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"The assert statements are being used to check a precondition--something that must be true when the method is invoked".


This is perfectly true,as far as the use of assertions is considered.But there are other conditions that has to be met for an assertion to be appropriate(Please note the word appropriate-not valid).One of these is
"Do not use assertions to validate arguments to a public method."
Which is done in your code.This is perfectly legal,but is not an appropriate way to use assertions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic