CodeQL 文档

hashCode 中的拼写错误

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

点击查看 CodeQL 仓库中的查询

名为 hashcode 的方法可能是拼写错误。可能本意是使用 hashCode(不同的大小写)。

建议

确保任何此类方法的命名都是故意的。即使是故意的,也最好将其重命名,以避免与继承的方法 Object.hashCode 混淆。

示例

以下示例显示了一个名为 hashcode 的方法。最好对其进行重命名。

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();
	}
}

参考

  • ©GitHub, Inc.
  • 条款
  • 隐私