Inspectopedia
 
2024.3

Local variable hides field

Warning
New
Last modified: 03 December 2024

Reports local variables named identically to a field of a surrounding class. As a result of such naming, you may accidentally use the variable where the identically named field is intended.

A quick-fix is suggested to rename the variable.

Example:

You can configure the following options for this inspection:

  1. Ignore non-accessible fields - ignore local variables named identically to superclass fields that are not visible (for example, because they are private).

  2. Ignore local variables in a static context hiding non-static fields - for example when the local variable is inside a static method or inside a method which is inside a static inner class.