Skip to content

簡介

  • js callback function <=> lambda(FunctionalInterface)
  • 回調函數
  • 傳動作、傳方法
function javascriptCallback (a , callback){
    if(callback){
        callback();
    }
}
// Interface Function<T   ,R   >
// Interface Function<參數,返回值>
public Integer javaLamdba(Integer a ,java.util.Function<Integer,Integer> fun) {
    fun.apply(a);
}


Integer intReturnValue = javaLamdba(2 , param -> param * param );
Integer intReturnValue = javaLamdba(2 , param -> param + param );
Integer intReturnValue = javaLamdba(2 , param -> param / param );

內容

  • Consumer,(unary function from T to void)
  • Function,(unary function from T to R)
  • Predicate,(unary function from T to boolean)
  • Supplier,(nilary function to R)

Consumer

Function

Predicate

Supplier

參考資料