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 — Class has same name as super class — CodeQL query help documentation

Class has same name as super class¶

ID: java/class-name-matches-super-class
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
Tags:
   - quality
   - maintainability
   - readability
   - naming
Query suites:
   - java-code-quality.qls
   - java-security-and-quality.qls

Click to see the query in the CodeQL repository

A class that has the same name as its superclass may be confusing.

Recommendation¶

Clarify the difference between the subclass and the superclass by using different names.

Example¶

In the following example, it is not clear that the attendees field refers to the inner class Attendees and not the class com.company.util.Attendees.

import com.company.util.Attendees;

public class Meeting
{
	private Attendees attendees;

	// ...
	// Many lines
	// ...

	// AVOID: This class has the same name as its superclass.
	private static class Attendees extends com.company.util.Attendees
	{
		// ...
	}
}

To fix this, the inner class should be renamed.

References¶

  • R. C. Martin, Clean Code: A Handbook of Agile Software Craftsmanship, §17.N4. Prentice Hall, 2008.

  • © 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.