JDK8-函数式接口
返回类型为void的函数
TYPE OF FUNCTION | LAMBDA EXPRESSION | KNOWN FUNCTIONAL INTERFACES |
Nullary | () -> doSomething() | Runnable |
Unary | foo -> System.out.println(foo) | Consumer IntConsumer LongConsumer DoubleConsumer |
Binary | (console,text) -> console.print(text) | BiConsumer ObjIntConsumer ObjLongConsumer ObjDoubleConsumer |
n-ary | (sender,host,text) -> sender.send(host, text) | Define your own |
返回类型为T的函数
TYPE OF FUNCTION |
LAMBDA EXPRESSION |
KNOWN FUNCTIONAL INTERFACES |
Nullary | () -> ”Hello World” | Callable Supplier BooleanSupplier IntSupplier LongSupplier DoubleSupplier |
Unary | n -> n + 1 n -> n >= 0 | Function IntFunction LongFunction DoubleFunctionIntToLongFunction IntToDoubleFunction LongToIntFunction LongToDoubleFunction DoubleToIntFunction DoubleToLongFunctionUnaryOperator IntUnaryOperator LongUnaryOperator DoubleUnaryOperatorPredicate IntPredicate LongPredicate DoublePredicate |
Binary | (a,b) -> a > b ? 1 : 0(x,y) -> x + y (x,y) -> x % y == 0 | Comparator BiFunction ToIntBiFunction ToLongBiFunction ToDoubleBiFunctionBinaryOperator IntBinaryOperator LongBinaryOperator DoubleBinaryOperatorBiPredicate |
n-ary | (x,y,z) -> 2 * x + Math.sqrt(y) – z | Define your own |