Simple Lambda – Java8

public class LambdaSample {
  protected interface SimpleCalc {
    int operation(int a, int b);
  public static void main(String[] args) {
     * Old style
    SimpleCalc add = new SimpleCalc() {
    public int operation(int a, int b) {
      return a + b;
  System.out.println(add.operation(2, 5));
   * New style - Lambda Expression
  SimpleCalc multiply = (a, b) -> a * b;
  System.out.println(multiply.operation(2, 5));

In the above code you can see the old vs new style of anonymous function creation. Lambda expression makes it short, concise and readable. [its look readable to me :)]


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 )

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.