• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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!
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic