Checkstyle says:
Class should define a constructor.
PMD says:
Avoid unnecessary constructors - the compiler will generate these for you.
Who is right? Or let's put it this way - what are the pros and cons of having an empty default ctor in a class?
I like PMD's answer. The less code the better. Don't write constructors the compiler will write for you.
My impression is that the main argument for writing the constructor is that some poor programmer who doesn't understand how constructors work in Java might stumble over your code and get confused. I don't like writing code that is needlessly obscure but I don't like writing dumbed-down code either.
But this is me being obsessive and probably unreasonable. There is a world of application programmers whose central focus is on the business, not on the language, and who are not language experts. A survival technique a lot of people use is to have a consistent style, whether it is absolutely necessary is not the point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With