Last active
August 29, 2015 14:00
-
-
Save iaveryanov/11140344 to your computer and use it in GitHub Desktop.
Puzzle solution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru; | |
// origin source: http://arhipov.blogspot.ru/2014/02/java-8-lambdas-unintentional-puzzle.html | |
// my gist with puzzle https://gist.github.com/iaveryanov/10990181 | |
public class Forrest { | |
public Runnable wrooom(){ | |
return new Runnable() { | |
@Override | |
public void run() { | |
System.out.println("Hello, lambda!"); | |
} | |
}; | |
} | |
public static void main(String[] args) { | |
Forrest forrest = new Forrest(); | |
Runnable runnable = forrest.wrooom(); | |
/** | |
* Method reference forrest::wrooom will expand to | |
*/ | |
Runnable runnable2 = new Runnable() { | |
@Override | |
public void run() { | |
// not print | |
forrest.wrooom(); // return new Runnable, but will not be called run() with println! | |
// will print | |
// forrest.wrooom().run(); // return new Runnable and call run! | |
} | |
}; | |
runnable.run(); // print "Hello, lambda!" | |
runnable2.run(); // print nothing, only create new Runnable! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment