Since Checkstyle 3.4
Checks that classes (except abstract ones) define a constructor and don't rely on the default one.
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="MissingCtor"/>
</module>
</module>
Example:
class ExampleOk { // OK
private int a;
ExampleOk(int a) {
this.a = a;
}
}
class ExampleDefaultCtor { // OK
private String s;
ExampleDefaultCtor() {
s = "foobar";
}
}
class InvalidExample { // violation, class must have a constructor.
public void test() {}
}
abstract class AbstractExample { // OK
public abstract void test() {}
}
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.coding