Inspectopedia Help

Parameter hides field

Reports method parameters named identically to a field of a surrounding class. As a result of such naming, you may accidentally use the parameter when using the identically named field is intended.

A quick-fix is suggested to rename the parameter.

Example:

class Main { private String value; public Main(String value) { value = value.toUpperCase(); } }

You can configure the following options for this inspection:

  1. Ignore for property setters - ignore parameters of simple setters.

  2. Ignore superclass fields not visible from subclass - ignore private fields in a superclass, which are not visible from the method.

  3. Ignore for constructors - ignore parameters of constructors.

  4. Ignore for abstract methods - ignore parameters of abstract methods.

  5. Ignore for static method parameters hiding instance fields - ignore parameters of static methods hiding an instance field and to ignore parameters of instance methods in static inner classes hiding an instance field of an outer class. While not strictly hiding, such parameters can still be confusing.

Inspection options

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

Ignore for property setters

Not selected

Ignore superclass fields not visible from subclass

Default: Selected

Ignore for constructors

Not selected

Ignore for abstract methods

Not selected

Ignore for static method parameters hiding instance 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