• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assertions and parameters

 
Jasper Vader
Ranch Hand
Posts: 284
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
today's question from examulator gave 1/, 2/, and 3/, as correct answers, but the thing is, i understand that assertions should NOT be used to validate user input, such as parameters given at the command-line etc... but inner methods parameters are okay to be checked by assertions arent they?
here is the question...
Which of the following statements are true?

1 Compiling code with assertions requires a compilation switch
2 Assertions should not be used for parameter checking
3 Programs should not depend on the outcome of assertions
4 The use of assertions requires the code should import java.assert.*
 
Dan Culache
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was my understanding too.
DO NOT use assertions to validate parameters for public methods.
DO use assertions for all other parameter validation.
So with the above caveat I believe the answers are:
2&3
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a mail in the afternoon giving feedback about this ambiguity to Marcus. I hope to get a reply
Sri
 
Jasper Vader
Ranch Hand
Posts: 284
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the responses ...
btw //1 is correct because yes, assertions do require a compilation switch.
but //2 is ambiguous as assertions should and should not be used for parameter checking, yes if it is parameters from other methods but no if it is a parameter directly from a user input.
Sri - i would be interested to see what marcus says .
 
Rahul Gupta
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Recently I appeared for the SCJP test and there was a question similar to this. But there was not scope for any ambiguity. So dont worry and just have a clear idea of where assertions can or cannot be used. The Exam question will be clear enough and will not confuse you if you know the stuff. Hope that helps
rahul
 
Jasper Vader
Ranch Hand
Posts: 284
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cheers Rahul
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic