---
# System prepended metadata

title: 進階的內建 functional interfaces
tags: [Java, "Java\_Lambda"]

---

# 進階的內建 functional interfaces
分兩類：
1. 四種基礎介面
2. Operator 介面

## 基礎介面
### Predicate
|名稱|參數型別 -> 回傳型別|
|-|-|
|`Predicate<T>`|`T` -> `boolean`|
|`IntPredicate`|`int` -> `boolean`|
|`LongPredicate`|`long`-> `boolean`|
|`DoublePredicate`|`double`-> `boolean`|
|`BiPredicate<T, U>`|(`T`, `U`) -> `boolean`|

### Consumer
|名稱|參數型別 -> 回傳型別|
|-|-|
|`Consumer<T>`|`T` -> `void`
|`IntConsumer`|`int` -> `void`|
|`LongConsumer`|`long` -> `void`|
|`DoubleConsumer`|`double` -> `void`|
|`BiConsumer<T, U>`|(`T`, `U`) -> `void`|
|`ObjIntConsumer<T>`|(`T`, `int`) -> `void`|
|`ObjLongConsumer<T>`|(`T`, `long`) -> `void`|
|`ObjDoubleConsumer<T>`|(`T`, `double`) -> `void`|

### Function
|名稱|參數型別 -> 回傳型別|
|-|-|
|`Function<T, R>`|`T` -> `R`|
|`IntFunction<R>`|`int` -> `R`|
|`LongFunction<R>`|`long` -> `R`|
|`DoubleFunction<R>`|`double` -> `R`|
|`ToIntFunction<T>`|`T` -> `int`|
|`ToLongFunction<T>`|`T` -> `long`|
|`ToDoubleFunction<T>`|`T` -> `double`|
|`IntToLongFunction`|`int` -> `long`|
|`IntToDoubleFunction`|`int` -> `double`|
|`LongToIntFunction`|`long` -> `int`|
|`LongToDoubleFunction`|`long` -> `double`|
|`DoubleToIntFunction`|`double` -> `int`|
|`DoubleToLongFunction`|`double` ->`long`|
|`BiFunction<T, U, R>`|(`T`, `U`) -> `R`|
|`ToIntBiFunction<T, U>`|(`T`, `U`) -> `int`|
|`ToLongBiFunction<T, U>`|(`T`, `U`) -> `long`|
|`ToDoubleBiFunction<T, U>`|(`T`, `U`) -> `double`|

### Supplier
|名稱|參數型別 -> 回傳型別|
|-|-|
|`Supplier<T>`|() -> `T`|
|`BooleanSupplier`|() -> `boolean`|
|`IntSupplier`|() -> `int`|
|`LongSupplier`|() -> `long`|
|`DoubleSupplier`|() -> `double`|

## Operator 介面
Operator：特指參數型別和回傳型別一致的功能(Function)，有一元操作(UnaryOperator)和二元操作(BinaryOperator)兩種。
### UnaryOperator
|名稱|參數型別 -> 回傳型別|
|-|-|
|`UnaryOperator<T>`|`T` -> `T`|
|`IntUnaryOperator`|`int` -> `int`|
|`LongUnaryOperator`|`long` -> `long`|
|`DoubleUnaryOperator`|`double` -> `double`|

### BinaryOperator
|名稱|參數型別 -> 回傳型別|
|-|-|
|`BinaryOperator<T, T>`|(`T`, `T`) -> `T`|
|`IntBinaryOperator`|(`int`, `int`) -> `int`|
|`LongBinaryOperator`|(`long`, `long`) -> `long`|
|`DoubleBinaryOperator`|(`double`, `double`) -> `double`|
