Why the assertion is not usually used in deployment ?
I studied that asserting the public method arguments is inappropriate..but asserting private method arguments is appropriate in deployment..why ?
Why the assertion is not usually used in deployment ? I studied that asserting
Share
Assertions are not enabled by default, you have to pass the
-eaparameter to the JVM to enable them. So in many cases, it may be a simple omission in deployment. Other reasons may be performance (I have no evidence that asserts would noticeably slow down execution though), or proper error handling, i.e. it may be deemed inappropriate for the production system to throwAssertionErrors live.Asserting private method arguments is appropriate because you are supposed to be in full control over the arguments passed to them. Public methods OTOH are called from the outside world, so you may have no control over the concrete arguments passed, thus it is better to do explicit argument checks and handle invalid arguments appropriately (e.g. by throwing a suitable runtime exception such as
IllegalArgumentException), or for null references, let the JVM throw aNullPointerException.