MissingCtor
Since Checkstyle 3.4
Description
Checks that classes (except abstract ones) define a constructor and don't rely on the default one.
Compatibility note: when creating an explicit constructor already in existing class that used by other in codebases that you do not own, it must match precisely the declaration of the automatically generated constructor; even if the constructor should logically be protected, it must be made public to match the declaration of the automatically generated constructor, for compatibility.
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="MissingCtor"/>
</module>
</module>
Example:
public class Example1 {
private int a;
Example1(int a) {
this.a = a;
}
}
class ExampleDefaultCtor {
private String s;
ExampleDefaultCtor() {
s = "foobar";
}
}
class InvalidExample { // violation, 'Class should define a constructor'
public void test() {}
}
abstract class AbstractExample {
public abstract void test();
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Fully Qualified Name
com.puppycrawl.tools.checkstyle.checks.coding.MissingCtorCheck
Use this fully qualified class name in configuration when an exact class reference is required.






