beauty of lambda

foreEach in the library takes a Consumer Interface implementation as argument. The problem is that the implementation of Consumer Interface is an anonymous class and is clumsy.

pointList.forEach(new Consumer<Point>() { 
        public void accept(Point p) { 
            p.move(p.y, p.x);

lambdas make things so simply

 pointList.forEach(p -> p.move(p.y, p.x)); 

code snippets and ideas taken from Maurice’s blog post

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: