Java8支持在接口中的实现方法

Java8的接口新特性

接口:

public interface Test8Interface {

    default String hello(String hello){
        hello = "HELLO" + hello;
        return sayHi(hello);
    }

    String sayHi(String hello);
}

实现类A:

public class HelloWorld implements Test8Interface {
    @Override
    public String sayHi(String hello) {
        return hello;
    }
}

实现类B:

public class HelloGood implements Test8Interface {
    @Override
    public String sayHi(String hello) {
        return hello;
    }
}

你可能感兴趣的:(初学,Java8)