/**
* Interface ToIntFunction<T>
* 計算 int 值的函數可以用來拆包
* ToIntFunction<T>
* ToLongFunction<T>
* ToDoubleFunction<T> 這三個方法作用類似,不再贅述
*/
ToIntFunction<Integer> toIntFunction=x->x;
int i = toIntFunction.applyAsInt(new Integer(5));
ToIntFunction toIntFunction1=x-> {
System.out.println("放個代碼塊看看 "+x);
return 5;
};
System.out.println(toIntFunction1.applyAsInt("PangHao"));
/**
* Interface IntFunction<R>
* 表示一個接受int值參數併產生結果的函數。 這是int消耗原始專業Function 。
* 這是一個functional interface的功能方法是apply(int) 。
* IntFunction<R>
* LongFunction<R>
* DoubleFunction<R> 這三個方法作用類似,不再贅述
*/
IntFunction intFunction =x->"傳進來了個int值:"+x;
Object apply2 = intFunction.apply(5);
System.out.println(apply2);
/**
* Interface BiFunction<T,U,R>
* T - 函數的第一個參數的類型
* U - 函數的第二個參數的類型
* R - 函數結果的類型
* 表示接受兩個參數併產生結果的函數。 這是二位一體的專業化Function 。
* 這是一個functional interface的功能方法是apply(Object, Object) 。
*/
BiFunction<Integer,Integer,String> biFunction =(x,y)->x+"+"+y+"="+(x+y);
String apply = biFunction.apply(3, 5);
System.out.println(apply);
/**
* Interface UnaryOperator<T>
* T - 操作數的類型和運算符的結果
* 對類型爲T的對象進行一元運算, 並返回T類型的結果表示對單個操作數產生與其操作數相同類型的結果的操作。
* 對於操作數和結果是相同類型的情況,這是Function的專業化。
* 這是一個functional interface,其功能方法是Function.apply(Object) 。
*
*/
UnaryOperator<Integer> unaryOperator=x->x+5;
Integer apply1 = unaryOperator.apply(5);
System.out.println(apply1);
/**
* Interface BiConsumer<T,U>
* T - 操作的第一個參數的類型
* U - 操作的第二個參數的類型
* 表示接受兩個輸入參數並且不返回結果的操作。 這是Consumer的二元專業化。 與大多數其他功能接口不同, BiConsumer預期通過副作用進行操作。
* 這是一個functional interface的功能方法是accept(Object, Object)
*/
BiConsumer biConsumer=(x,y)-> {
System.out.println("參數1是:"+x);
System.out.println("參數2是:"+y);
};
biConsumer.accept("PangHao","ZhangSan");
/**
* Interface BinaryOperator<T>
* T - 操作數的類型和操作符的結果
* 表示對同一類型的兩個操作數的操作,產生與操作數相同類型的結果。 對於操作數和結果都是相同類型的情況,
* 這是一個BiFunction的專業化。
* 這是一個functional interface的功能方法是BiFunction.apply(Object, Object) 。
*/
BinaryOperator<Integer> binaryOperator =(x,y)->x+y;
Integer apply3 = binaryOperator.apply(3, 5);
System.out.println(apply3);