GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CodeQL documentation
  • CodeQL overview
  • Writing CodeQL queries
  • CodeQL language guides
  • QL language reference
  • CodeQL standard-libraries
  • CodeQL query help
  • CodeQL repository
  • QL publications
  • CodeQL query help for C and C++
  • CodeQL query help for C#
  • CodeQL query help for GitHub Actions
  • CodeQL query help for Go
  • CodeQL query help for Java and Kotlin

This view

  • Original page
  • New address

GeezerVison is showing codeql.github.com — Typo in equals — CodeQL query help documentation

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¶

  • Java API Specification: equals.

  • © GitHub, Inc.
  • Terms
  • Privacy
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.