Hi,
Please help with the following question from Dan's exam.
Which statements are true?
a. Assertions should not be used to validate arguments passed to public methods.
b. Assertions should not be used to validate arguments passed to nonpublic methods.
c. Assertions should not be used within the default case of a switch statement.
d. Assertions should not be used to perform processing that is required for the normal operation of the application.
The answer given is only a,d. why not, a,b,d?
The
Java documentation on Assertions says that..
Do not use assertions to check the parameters of a public method. An assert is inappropriate because the method guarantees that it will always enforce the argument checks. It must check its arguments whether or not assertions are enabled. Further, the assert construct does not throw an exception of the specified type. It can throw only an AssertionError.
My question is, even a non-public method can be called by any public method or any other sub classes. Why, assertions need not be used only with public methods but can be used with others? Can any one clarify.
Thanks and Regards,
Rama