3 ms·
So they should add that mutating arguments during object construction may lead to not-so-successfully constructed (invalid) object. __Mission failed successfull
by ris58h 3y ago
So they should add that mutating arguments during object construction may lead to not-so-successfully constructed (invalid) object.
__Mission failed successfully__
- layer8 3y agoNo. The job of a constructor is to establish the class’s invariants for the new instance, or else fail with an exception. This bug in the String class fails to do so.
- ris58h 3y ago> The job of a constructor is to establish the class’s invariants for the new instance, or else fail with an exception. Could you refer such statement in Java specification?
- jdmichal 3y agoInvariants and all methods -- including constructors -- enforcing them is OOP 101. I would be surprised if they felt the need to make such a callout in the language specification.