Skip to content

Instantly share code, notes, and snippets.

@iamcrypticcoder
Created April 18, 2018 16:37
Show Gist options
  • Save iamcrypticcoder/d981daca9051d193bbac1b2ece3abe35 to your computer and use it in GitHub Desktop.
Save iamcrypticcoder/d981daca9051d193bbac1b2ece3abe35 to your computer and use it in GitHub Desktop.
public class ConsumerDemo {
static class Point {
Double x, y;
public Point(Double x, Double y) {
this.x = x;
this.y = y;
}
}
public static void main(String... args) {
Point point = new Point(1.0, 2.0);
Consumer<Point> pointPrinter1 = (p) -> System.out.printf("x = %f, y = %f\n", p.x, p.y);
Consumer<Point> pointPrinter2 = (p) -> System.out.printf("(%f, %f)\n", p.x, p.y);
pointPrinter1.accept(point);
pointPrinter2.accept(point);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment