Java Stream How to - Call both default method and lambda method from an interface








Question

We would like to know how to call both default method and lambda method from an interface.

Answer

//  w ww .ja  va  2  s  . c o m
public class Main {

    public static void main(String[] args) {

        ChildInterface def = (s) -> {
            System.out.println("lambda: " + s);
        };
        def.doIt();
        def.likeIt("I like the IExtended..");
    }
}

interface ChildInterface extends ParentInterface {

    public default void doIt() {
        System.out.println("my extended doIt function..");
    }
}

interface ParentInterface {
    public void likeIt(String s);
    public default void doIt() {
        System.out.println("doIt function..");
    }
}

The code above generates the following result.