Last active
March 16, 2017 02:20
-
-
Save carlosmaniero/fd5faed4d93faf6d9a0bd80164cd367b to your computer and use it in GitHub Desktop.
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
interface TouchCallback { | |
public void apply(int times); | |
} | |
class TouchMe { | |
private int times = 0; | |
private TouchCallback onTouch; | |
TouchMe(TouchCallback onTouch) { | |
this.onTouch = onTouch; | |
} | |
public void touch() { | |
onTouch.apply(++times); | |
} | |
} | |
public class LambdaExpressionExample { | |
public static void main(String args[]) { | |
TouchMe touchMe = new TouchMe(new TouchCallback() { | |
@Override | |
public void apply(int times) { | |
System.out.println(times); | |
} | |
}); | |
touchMe.touch(); // 1 | |
touchMe.touch(); // 2 | |
touchMe.touch(); // 3 | |
touchMe.touch(); // 4 | |
touchMe.touch(); // 5 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment