Skip to content

Instantly share code, notes, and snippets.

@carlosmaniero
Last active March 16, 2017 02:20
Show Gist options
  • Save carlosmaniero/fd5faed4d93faf6d9a0bd80164cd367b to your computer and use it in GitHub Desktop.
Save carlosmaniero/fd5faed4d93faf6d9a0bd80164cd367b to your computer and use it in GitHub Desktop.
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