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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

OCAJO1
Posts: 221
Joined: Mon Nov 26, 2018 2:43 pm
Contact:

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

Post by OCAJO1 »

Nice to know that lambdas don't change the local variable scope rules.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests