Java8函数委托——无参&获取一个数值类型返回——DoubleSupplier

原创
06/23 11:20
阅读数 10

1.code

class PersonBean {
    private double high;
    private double weight;

    public PersonBean(double high, double weight) {
        this.high = high;
        this.weight = weight;
    }

    public double getHigh() {
        System.out.println("身高:" + high);
        return high;
    }

    public double getWeight() {
        System.out.println("体重:" + weight);
        return weight;
    }
}

public class DoubleSupplierTest {

    public static void main(String[] args) {

        PersonBean personBean = new PersonBean(179.68, 73.16);

        DoubleSupplier highSupplier = personBean::getHigh;

        DoubleSupplier weightSupplier = personBean::getWeight;

        highSupplier.getAsDouble();

        weightSupplier.getAsDouble();

    }

}

2.结果

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部
返回顶部
顶部