MissingCtor

Since Checkstyle 3.4

Description

Checks that classes (except abstract ones) define a constructor and don't rely on the default one.

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.

Package

com.puppycrawl.tools.checkstyle.checks.coding

Parent Module

TreeWalker