Page 1 of 1

[HD Pg 372, Sec. 12.5.4 - scope-of-variables-in-a-lambda-expression]

Posted: Thu May 02, 2019 7:32 pm
by OCAJO1
Just so I'm clear about this. The section talks about variable x not being effectively final because its value changes later on in the code. So when an attempt is made to "use" a variable within the body of a lambda expression, lambda checks the scope of what - its method, its class, all the classes in the program, to see if the variable is final or effectively final?

Please feel free to over elaborate :) Thanks

Re: [HD Pg 372, Sec. 12.5.4 - scope-of-variables-in-a-lambda-expression]

Posted: Thu May 02, 2019 8:32 pm
by admin
Scope of a local variable is within that method. It cannot be accessed from anywhere else. So only the method code needs to be checked.

Re: [HD Pg 372, Sec. 12.5.4 - scope-of-variables-in-a-lambda-expression]

Posted: Fri May 03, 2019 12:16 pm
by OCAJO1
Nice to know that lambdas don't change the local variable scope rules.