In the article about first constructor rule, we’ve seen that classes must have at least one constructor, otherwise they are reduced to a sorry imitation of what they should be. We also concluded that the first constructor in a class must validate the parameters and just assign them to the fields and do nothing else. Here we’ll cover the next rule: why such constructors deserve to be called primary constructors and why classes must have exactly one of them.
No comments yet. Log in to reply on the Fediverse. Comments will appear here.