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:

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

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

  • Ignore for constructors - ignore parameters of constructors.

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

  • 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

Option

Type

Default

Ignore for property setters

Checkbox

false

Ignore superclass fields not visible from subclass

Checkbox

true

Ignore for constructors

Checkbox

false

Ignore for abstract methods

Checkbox

false

Ignore for static method parameters hiding instance fields

Checkbox

true

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023