CodeQL documentation

Class has same name as super class

ID: java/class-name-matches-super-class
Kind: problem
Security severity: 
Severity: recommendation
Precision: high
   - maintainability
   - readability
   - naming
Query suites:
   - 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.


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


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


public class Meeting
	private Attendees attendees;

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

	// AVOID: This class has the same name as its superclass.
	private static class Attendees extends
		// ...

To fix this, the inner class should be renamed.


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

  • © GitHub, Inc.
  • Terms
  • Privacy