Non-abstract classes and enums with non-static
, private
members should explicitly initialize those members, either in a
constructor or with a default value.
Noncompliant code example
class A { // Noncompliant
private int field;
}
Compliant solution
class A {
private int field;
A(int field) {
this.field = field;
}
}
Exceptions
- Class implementing a Builder Pattern (name ending with "Builder").
- Java EE class annotated with:
- Class and field annotated with:
- Field annotated with:
- Class annotated with: