In addition to all the previous arguments for the no-args constructor, it is a required element of JavaBeans, since these beans can be created using reflection (in particular, by calling Class.newInstance ). As a result, any JavaBeans-based framework will make this no-args constructor an essential part of your architecture.
There is also an added benefit, as the no-args constructor can help create some kind of free interface, allowing you to call setters. For example, in the company I worked for, it is used to determine next to setters and getters with the following methods:
class MyClass { privaite int index; public int getIndex() { return index; } public void setindex(int index) { this.index = index; } public MyClass withIndex(int index) { setIndex(index); return this; } }
Lets me create objects as follows:
MyClass myObject = new MyClass().withIndex(2);
This was a very useful way to create objects without defining error constructors.
source share