集册 Java实例教程 避免接口代码中的冗余

避免接口代码中的冗余

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

474
Java 9可以在接口内包含私有方法。

interface MyInter{

    /* 来自 N o w J a v a . c o m - 时代Java*/

    public default double a(double length, double width, double depth){

        return myMethod(length, width, depth);

    }

 

    public default double b(double length, double width,double shallowDepth, double middleDepth, double deepDepth){

        return myMethod(length, width, 6);

    }

    

    /**

     * Standard square or rectangular volume calculation. 

     */

    static double myMethod(
展开阅读全文