File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assert statements

 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

my question is why assert statement on line1 is not appropriate?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it is validating an argument of a public method
 
Neha Daga
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Raju Champaklal
Ranch Hand
Posts: 521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
dimple bav
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic