org.sonar.l10n.java.rules.java.S2047.html Maven / Gradle / Ivy
Why is this an issue?
Well-named functions can allow the users of your code to understand at a glance what to expect from the function - even before reading the
documentation. Toward that end, methods returning a boolean should have names that start with "is" or "has" rather than with "get".
Noncompliant code example
public boolean getFoo() { // Noncompliant
// ...
}
public boolean getBar(Bar c) { // Noncompliant
// ...
}
public boolean testForBar(Bar c) { // Compliant - The method does not start by 'get'.
// ...
}
Compliant solution
public boolean isFoo() {
// ...
}
public boolean hasBar(Bar c) {
// ...
}
public boolean testForBar(Bar c) {
// ...
}
Exceptions
Overriding methods are excluded.
@Override
public boolean getFoo(){
// ...
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy