Java 8 lambda Void argument

前端 未结 9 649
臣服心动
臣服心动 2020-12-12 08:30

Let\'s say I have the following functional interface in Java 8:

interface Action {
   U execute(T t);
}

And for some cases I ne

9条回答
  •  天涯浪人
    2020-12-12 09:28

    I think this table is short and usefull:

    Supplier       ()    -> x
    Consumer       x     -> ()
    Callable       ()    -> x throws ex
    Runnable       ()    -> ()
    Function       x     -> y
    BiFunction     x,y   -> z
    Predicate      x     -> boolean
    UnaryOperator  x1    -> x2
    BinaryOperator x1,x2 -> x3
    

    As said on the other answers, the appropriate option for this problem is a Runnable

提交回复
热议问题