Java generating a parameterless constructor when you don't have any other is like a polite waiter taking your coat for you.
Java still generating a parameterless constructor after you define another version of it is like the same waiter taking the coat off you after you gave a clear indication that you have your own plans of what to do with the coat.
If I have a class (that I want to be immutable):
final String firstName;
final String lastName;
And I add a constructor:
Person(String firstName, String lastName)
this.firstName = firstName;
this.lastName = lastName;
And Java was still to provide a default, parameterless constructor, then this code can't compile, because
lastName fields are declared as final, yet they are not set after you call
Person p = new Person().
You are forcing me to provide another implementation:
this.firstName = null; // or "", or whatever
this.lastName = null;
And since I don't want it - as it's useless, I might feel inclined to put skull and crossbones on it:
// don't use this constructor! i don't want it to ever be called!
throw new RuntimeException("Illegal constructor called");
But I still can't forbid another developer to create a method (inside the
Person class, so marking the constructor as private didn't help):
public static Person createPerson()
return new Person(); // this will blow in our face
All this fuss could be - and is - avoided thanks to the fact that Java (and not only Java) works the way it works.
If you define a method
setCoordinates(int x, int y), you don't expect compiler to automatically accept a parameterless version of it -
setCoordinates(). It wouldn't do a thing.
How is this different from expecting a parameterless constructor? Well, obviously, a constructor always does at least one thing - it creates an object (or dies trying).
But I like to be in control of how I want my objects to be instantiated. Forcing me to have a parameterless constructor no matter what I do takes this control away from me.