Laden...
Hi again,
I sent a puzzle that might have confused you :-)
That could be because the sayHello() method was supposed to be non-static *blush*. Make it a non-static private method, and you will see a difference between using an anonymous inner class and a lambda. The question of course is why this would make a difference, which you can trace back to how inner classes were hacked into Java 1.1. Enough hints :-)
public class SlowGreeter {
static {
new SlowGreeter();
}
private void sayHello() {
System.out.println("Hello Slackers!!!");
}
public SlowGreeter() {
Thread thread = new Thread(new Runnable() {
public void run() {
sayHello();
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public static void main(String... args) {
System.out.println("We love sharing knowledge :-)");
}
}
Funnily enough, if you make sayHello() package access, then they both behave the same way.
Kind regards from Crete
Heinz
If you no longer wish to receive our emails, click the link below:
https://iw127.infusionsoft.com/app/optOut/8/a6ca3d5100f0d052/3347003/5ad96a864e0a5cdf
Cretesoft Limited 77 Strovolos Ave Strovolos, Lefkosia 2018 Cyprus
Laden...
Laden...