public static void test1() {
happyTime(3, (day) ->System.out.println("今天是第" + day + "天"));
}
public static void happyTime(int day, Consumer consumer) {
consumer.accept(day);
}
Supplier 型,無參有返System.out.print("3-9=");
return 9;
});
}
public static void minus(int n, Supplier supplier) {
Integer t = (Integer) supplier.get();
System.out.println(n - t);
}
Functionpublic static void test3() {
String str = "123";
add(6, str, (s) ->Integer.parseInt(str));
}
public static void add(int n, String str, Function function) {
Integer t = (Integer) function.apply(str);
System.out.println(t + n);
}
Predicate,判斷型public static void test4() {
int n = -5;
guess(n, (number) ->{
if (n >0) return true;
return false;
});
}
public static void guess(int n, Predicate predicate) {
boolean isFlag = predicate.test(n);
System.out.println(isFlag);
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
本文標(biāo)題:JAVA中Lambda表達式與四大常用函數(shù)式接口-創(chuàng)新互聯(lián)
網(wǎng)頁地址:http://chinadenli.net/article16/desjgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、外貿(mào)網(wǎng)站建設(shè)、做網(wǎng)站、營銷型網(wǎng)站建設(shè)、面包屑導(dǎo)航、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)