This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.*
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
I have written a mail in the afternoon giving feedback about this ambiguity to Marcus. I hope to get a reply Sri
Joined: Jan 10, 2003
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 .
hi, Recently I appeared for the SCJPtest 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
regards,<p>rahul <p>SCJP 1.4<br />--------<br />Life is great, make it meaningful<br />---------------------------------