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:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
FieldNameHidesFieldInSuperclass- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
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
staticfields which hidestaticfields 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 value:
Selected- Ignore static fields hiding static fields
Default value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |