Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Assertion

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I was reading tutorial on java which says

1)"Assertions can be used to validate the parameters passed to a private method."
2)"However,assertions should not be used to validate parameters passed to public methods because a public method must check its arguments regardless of whether assertions are enabled or not."

Could any one explain above statements with example code please.........

Thanks in advance,
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reg assertions i think the above two points are about which one is appropriate and which is not.

Have a glance on the following

1)First point is assertions are not going to be there when the application is deployed.

2)Second one is public methods can be called from anywhere and anytime.
If u use assertions the parameters are not going to be validated at
runtime because Refer point one

3)The lastone is private methods r called from with in a class u can assure
abt the values.

hmmm .....

simply private methods are under our control
whereas public ones r not in our hand.

Hope it is cleared and i don't think extra code is required.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Girish, welcome to JavaRanch!

To get better responses in the future, please make your subject lines more descriptive (especially when posting multiple questions on similar topics). Thanks!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic