resources.report.rules.pmd.ConstantsInInterface.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sanity4j Show documentation
Show all versions of sanity4j Show documentation
Sanity4J was created to simplify running multiple static code
analysis tools on the Java projects. It provides a single entry
point to run all the selected tools and produce a consolidated
report, which presents all findings in an easily accessible
manner.
ConstantsInInterface
ConstantsInInterface
Avoid constants in interfaces. Interfaces should define types, constants are implementation details better placed in classes or enums. See Effective Java, item 19.
//ClassOrInterfaceDeclaration[@Interface='true'][$ignoreIfHasMethods='false' or not(.//MethodDeclaration)]//FieldDeclaration
Example(s):
public interface ConstantInterface {
public static final int CONST1 = 1; // violation, no fields allowed in interface!
static final int CONST2 = 1; // violation, no fields allowed in interface!
final int CONST3 = 1; // violation, no fields allowed in interface!
int CONST4 = 1; // violation, no fields allowed in interface!
}
// with ignoreIfHasMethods = false
public interface AnotherConstantInterface {
public static final int CONST1 = 1; // violation, no fields allowed in interface!
int anyMethod();
}
// with ignoreIfHasMethods = true
public interface YetAnotherConstantInterface {
public static final int CONST1 = 1; // no violation
int anyMethod();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy