← 返回首页
Typo in hashCode — CodeQL query help documentation CodeQL docs
CodeQL documentation
CodeQL resources

Typo in hashCode

ID: java/hashcode-typo Kind: problem Security severity: Severity: warning Precision: medium Tags: - quality - reliability - correctness - readability Query suites: - java-security-and-quality.qls

Click to see the query in the CodeQL repository

A method named hashcode may be a typographical error. hashCode (different capitalization) may have been intended instead.

Recommendation

Ensure that any such method is intended to have this name. Even if it is, it may be better to rename it to avoid confusion with the inherited method Object.hashCode.

Example

The following example shows a method named hashcode. It may be better to rename it.

public class Person { private String title; private String forename; private String surname; // ... public int hashcode() { // The method is named 'hashcode'. int hash = 23 * title.hashCode(); hash ^= 13 * forename.hashCode(); return hash ^ surname.hashCode(); } }

References