In paragraph 2 of the books “Effective Java, 2nd Edition” there is this snippet of code in which the author wants to prohibit empty object initialization.
class example {
Private Example () {
Throw New Assertionerror ();
}
}
I am confusing the type of exclusion excited.
I do not understand why assertionerror is excited. Whether due to the lack of a more suitable type of exception, then because it should be so easy.
As far as I understand, this exception is excited when the Assert check does not pass. Also in Javadoc is simply written
[An Assertionerror IS] Thrown to Indicate That An Assertion Has Failed.
But I do not see that any Assert (verification of true-false assertion) was performed here.
Of course, the approval “You do not have to create an instance of the element of this class” was broken, but if you follow this logic, we must all excite assertionerror everywhere, and this is clearly not what we do.
What would it not cost, I would excit
new illegalstateException ("Must Not Instantiate An Element Of This Class")
What’s wrong with this? In what cases should I excite Assertionerror in your own code?
Sorry, I just have a little doubt because I very often use this pattern in your own code and I want to be sure that I do everything right.
Translation DOPLUMI Member Question .
Answer 1, Authority 100%
The meaning of Assertionerror is that the developer considered it impossible.
In this way, if it ever occurs Assertionerror , this is a clear sign of programming error
Translation Answer Participant Henry .