Wednesday, April 1, 2020

Functional interfaces

Functional interfaces - examples:


@FunctionalInterface 
interface Walkable {
    public String walk();
}

@FunctionalInterface  
interface Sayable{  
    void say(String msg);

and after using:

        Walkable walkWithLambda = () -> {
            return "I want to walk around.";
        };
        walkWithLambda.walk();

        Sayable sayWithLambda = (msg) - > {
            System.out.println(msg);
        };
        sayWithLambda.say("I want to say something important!");

No comments: