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

Typo in equals

ID: java/equals-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 equal may be a typographical error. equals 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.equals.

Example

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

public class Complex { private double real; private double complex; // ... public boolean equal(Object obj) { // The method is named 'equal'. if (!getClass().equals(obj.getClass())) return false; Complex other = (Complex) obj; return real == other.real && complex == other.complex; } }

References