Java 8 Lambdas limitations: closures

Suppose we want to create a simple thread that only prints something on the console:

int answer = 42;
Thread t = new Thread(
  () -> System.out.println("The answer is: " + answer)
);

What if we changed the value of answer while the thread is executing?

In this article, I would like to answer this question, discussing the limitations of Java lambda expressions and consequences along the way.

The short answer is that Java implements closures, but there are limitations when we compare them with other languages. On the other hand, these limitations can be considered negligible.

To support this claim, I will show how closures play an essential role in a famous language as JavaScript.

Read more

Online! Again.

After a long absence, my site came back online! This time I decided to create a Blog using WordPress. With this blog I want to share any information, tips, algorithms and other stuff.

I’ve decided to write my posts in English: the first reason is that, in this way, I can talk to the whole world; the second reason is that I’m Italian and this is also an opportunity to write something in English. For the last reason, excuse me for any error!