Topics

Leave a Reply

4 Comments on "Java 8 Lambda Basics 19 – Closures in Lambda Expressions"

Notify of
avatar

Jarl Øystein Samseth
Guest
Jarl Øystein Samseth
23 days 19 minutes ago
You're tutorials are superb. However, I just wanted to note that you can change the value of variable b, inside the lambda expression. I may have misunderstood you, but I wouldn't call it final if I change the b-value in the lambda expression. Then again, I haven't fully grasped the "effectively final" expression.I tested it by the following code:public class Main { static int b=2; void a(Runnable r){r.run();} public static void main(String[] args) { Main m = new Main(); m.a(()-> System.out.println(b)); m.a(()-> {b++; System.out.println(b);}); System.out.println(b); Runnable x = () -> {b++; System.out.println(b);}; m.a(x); m.a(x); m.a(x); }}This gave the output:233456Hence b… Read more »
Guram Kankava
Guest
Guram Kankava
5 months 12 days ago

Thank you very much.

Baba Gilo
Guest
Baba Gilo
6 months 30 days ago

What do you think if we always use $ as the method name in functional interface?

Rookie Cookie
Guest
Rookie Cookie
7 months 3 hours ago

I remember closures in JavaScript course. Just interesting to compare.

wpDiscuz