• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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.
 
Happily living in the valley of the dried frogs with a few tiny ads.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic