?Supplier 接口
Supplier 接口是一個供給型的接口,其實,說白了就是一個容器,可以用來存儲數據,然后可以供其他方法使用的這么一個接口
*** Supplier接口測試,supplier相當一個容器或者變量,可以存儲值*/@Testpublic void test_Supplier() {//① 使用Supplier接口實現方法,只有一個get方法,無參數,返回一個值Supplier<Integer> supplier = new Supplier<Integer>() {@Overridepublic Integer get() {//返回一個隨機值return new Random().nextInt();}};System.out.println(supplier.get());System.out.println("********************");//② 使用lambda表達式,supplier = () -> new Random().nextInt();System.out.println(supplier.get());System.out.println("********************");//③ 使用方法引用Supplier<Double> supplier2 = Math::random;System.out.println(supplier2.get());}
?