File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
src/main/java/challenge31_40 Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ package challenge31_40 ;
2+
3+ /**
4+ * Method reference vs Lambda
5+ * Lambda expression as runnable implementation will be not executed only if we call the run method.
6+ * + in every run() call, a new instance is created (constructor call).
7+ * + Lambda is lazy
8+ *
9+ * Method reference
10+ * the constructor is called only one time, the method reference is called only if we call the run method.
11+ *
12+ * // TODO: 11/11/2019
13+ * what are the implementation we can pass to the Runnable interface.
14+ */
15+ public class Challenge_38 {
16+
17+ public static void main ( String [] args ) {
18+ Runnable universeImpactRunnable = () -> new ChuckNorris ().roundHouseKick ();
19+ Runnable galaxyImpactRunnable = new ChuckNorris ()::roundHouseKick ;
20+
21+ System .out .println ("The galaxy is finished = " );
22+
23+ universeImpactRunnable .run ();
24+ universeImpactRunnable .run ();
25+
26+ galaxyImpactRunnable .run ();
27+ galaxyImpactRunnable .run ();
28+ }
29+
30+ static class ChuckNorris {
31+ private static int numberOfKicks ;
32+ private int galaxyDamage ;
33+
34+ public ChuckNorris () {
35+ this .galaxyDamage = numberOfKicks ++;
36+ }
37+ void roundHouseKick (){
38+ System .out .println (this .galaxyDamage );
39+ }
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments