Is the above an appropriate use of assertions? Acc. to Whizlabs it is, but for me, a method is getting called which wouldn't be if assertions were disabled (the side-effect thing).
Or, is Whizlabs correct, only because the method does nothing "significant"? [ October 07, 2006: Message edited by: Aniket Patil ]
SCJP 5.0 | SCWCD 1.4 <br /> <br />If you don't know where you are going, any road will take you there!
Joined: Aug 03, 2002
The method is only called if assertions are enabled and an AssertionError is thrown. I think that we are meant to assume that the purpose of the message() method is just to produce an appropriate message for the AssertionError. It's hard to decide if it's good or bad in my opinion.
What is tabu is to call a method which changes the computational state of the program as part of the asserted clause (left of the colon). [ October 07, 2006: Message edited by: Barry Gaunt ]
Hi Ankit, You are right that "Assertions are disabled by default" . So During runtime of the code if they are not enabled then there wont be any output. If assertions are enabled then the output will be an Assertion Error.
Joined: Feb 20, 2006
Even though this assert statement calls a method, it does not have any side effects - the method does not change the state of the class. All the variable values stay the same.