集册 Java实例教程 使用默认方法是在接口中声明可选方法。

使用默认方法是在接口中声明可选方法。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

413
使用默认方法是在接口中声明可选方法。

interface Named {
/*
nowjava
*/

    void setName(String name);

    

    default String getName() {

        return "John Doe";

    }

    

    default void setNickname(String nickname) {

        throw new UnsupportedOperationException("setNickname");

    }

    

    default String getNickname() {
    /* from 
    N o w J a v a . c o m - 时代Java*/

        throw new UnsupportedOperationException("getNickname"); 

    }

}