Inspectopedia Help

Subclass field hides superclass field

Reports fields in a derived class that are named identically a field of a superclass. Java fields cannot be overridden in derived classes, so the field in the derived class will hide the field from the superclass.

As a result of such naming, you may accidentally use the field of the derived class where the identically named field of a base class is intended.

A quick-fix is suggested to rename the field in the derived class.

Example:

class Parent { Parent parent; } class Child extends Parent { Child parent; }

You can configure the following options for this inspection:

  1. Ignore non-accessible fields - indicates whether this inspection should report all name clashes, or only clashes with fields which are visible from the subclass.

  2. Ignore static fields hiding static fields - ignore static fields which hide static fields in base classes.

Inspection options

Here you can find the description of settings available for the Subclass field hides superclass field inspection, and the reference of their default values.

Ignore non-accessible fields

Default: Selected

Ignore static fields hiding static fields

Default: Selected

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024