Inspectopedia Help

Lambda parameter hides field

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

A quick-fix is suggested to rename the lambda parameter.

Example:

public class MyClass { public Object foo; void sort(List<Integer> list) { list.sort((foo, bar) -> foo - bar); } }

Use the option to choose whether to ignore fields that are not visible from the lambda expression. For example, private fields of a superclass.

Inspection options

Option

Type

Default

Ignore fields not actually visible from the lambda

Checkbox

true

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023