• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Regarding Assert

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assertions can be used to validate the parameters passed to a private method. However, assertions should not be used to validate parameters passed to public methods...WHY.......?(With Example)
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its not a shouldn't do thing that assertions not used to validate parameters to a public method. you can use assertions to validate parameters of a public method. But, its a good-to-do kind of thing to use assertion to validate parameters to only private methods. Because, the main purpose of assertion is that you are sure of a condition not going to occur but still to protect those conditions. If and only if the method is private, you can assure that a condition cannot happen because you are only going to use. But if it is a public method exposed to other classes, wrong parameters can be passed by one or the other more obviously. So, it is not good to use assertion to validate parameters to public methods (since a public method can receive wrong arguments more often than a private method).

sorry, I couldnt give an example since it is more of a design issue.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic