Lambda Expression in Java

Java Lambda Example

package it;

public class TypeInterfaceExample {

public static void main(String[] args) {

        StringLambdaString myLambda1 = (String s) -> s.length();

        StringLambdaString myLambda2 = (s) -> s.length();

        StringLambdaString myLambda3 = s -> s.length();

        printLambda(myLambda3);

        //OR

        printLambda(s -> s.length());//here directly the definition of the

        implemention of the method getLength

}

public static void printLambda(StringLambdaString l) {

        System.out.println(l.getLength(“Hello Lambda”));

}

        interface StringLambdaString {

               int getLength(String s);

        }

}

Thanks to Brains

Leave a Reply