File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assert statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assert statements" Watch "Assert statements" New topic
Author

Assert statements

Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504


which assert statements are used appropriately?
the answer is line2.

my question is why assert statement on line1 is not appropriate?


SCJP 1.6 96%
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Because it is validating an argument of a public method


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
thanks
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
because x is the parameter of a public method and it is inappropriate to check them.....because after all it is public method which can be accessed by any client....and the client doesnt know if there were supposed by a check on the argument passed to the method...


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
dimple bav
Ranch Hand

Joined: Sep 12, 2008
Posts: 90
Neha Daga wrote:

which assert statements are used appropriately?
the answer is line2.

my question is why assert statement on line1 is not appropriate?


----------------------------------------------
Its a rule that assertions should not be use to check the arguments passed to a public method

To know the reasons you can check SCJP5-Paul Sanghera CHP 7(pg 190).

I would like to know how assertions work with private methods ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assert statements