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:
You can configure the following options for this inspection:
Ignore non-accessible fields - indicates whether this inspection should report all name clashes, or only clashes with fields which are visible from the subclass.
Ignore static fields hiding static fields - ignore
static
fields which hidestatic
fields in base classes.
Inspection options
Option | Type | Default |
---|---|---|
Ignore non-accessible fields | Checkbox | true |
Ignore static fields hiding static fields | Checkbox | true |
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |