Default constructor is good or evil? Checkstyle and PMD are opposite here

Although I'm somewhat like lesser code but having default constructor make it easier to set a breakpoint whenever it is needed to debug.

Anyway, may I remind you that PMD's website also said that the issue is controversial :)


As with many decisions that are 'controversial', the truth is that it really doesn't matter that much. Write the constructor or don't. The effect on the quality and maintainbility of your code will be negligible. If you are coding with others then adopt the same style for consistency, but otherwise - do whichever you feel like.


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.


When the default constructor is the only constructor, it is 100% equivalent to write it explicitly with an empty body or to omit it. However, the compiler will not generate a default constructor if you have any explicitly defined constructors, default or not. This means that if you rely on the compiler to generate a constructor for you, and later add alternative constructors, then the default constructor goes away. Personally, I would tend toward letting the compiler do the generation anyway; if that default constructor was in use it will generate compile warnings and is easy to add at that point. Otherwise, why keep it around at all?