org.sonar.l10n.java.rules.squid.S1701.html Maven / Gradle / Ivy
The newest version!
It's confusing to have a class field with the same name as a method in the class. It's also confusing to have multiple fields that differ only in capitalization
Typically this situation indicates poor naming. Method names should be action-oriented, and thus contain a verb, which is unlikely in the case where both a method and a member have the same name. However, renaming a public method could be disruptive to callers. Therefore renaming the member is the recommended action.
Compliant Solution
public class Foo {
public static final String NAME_QUERY = "Select name from person";
private String queryString; // member has been renamed
public String query() {
// do something...
}
private void doSomething() {
String tmp = query; // results in a compile error
String tmp2 = query(); // no question now what was intended
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy