Why IDEA underscores a variable inside lambda-expression as if it is reassigned, though it is used just to return a value?

  Kiến thức lập trình

Given instance method

“void f() {
int var = 6;

Function<Integer, Integer> myFunc = (x) - {return var; };

}“`

var is underlined (only once – inside lambda).

Usually, if I really reassign (say writevar = 7after var = 6) – both occurrencies of var are underlined.
But in my case only occurrence inside lambda is underlined.

Could you please provide any comments concerning such IDE behavior?

I expected that there is no reassignment here and so var would not be underlined at all!

New contributor

user24504205 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT