Java @FunctionalInterface Function

Java @FunctionalInterface Function

[TOC]

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@FunctionalInterface
public interface Function<T,R>{
R apply(T t);

default <V> Function<V,R> compose(Function<? extends V,? extends T> before){
Objects.requireNonNull(before);
return (V v)-> apply(before.apply);
}


default <V> Function<T,V> andThen(Function<? super R,? superOb V> after){
Objects.requireNonNull(after);
return (T t)-> after.apply(apply(t));
}

static <T> Function<T, T> identity(){ return t -> t;}
}

介绍

Function<T,R> ,这里我翻译一下api上的内容

Type Parameters

T 函数的输入类型
R 函数的输出类型

All Known Subinterface

UnaryOperator

Functional Interface

这是一个函数式接口,因此可以作为lambda表达式或者方法引用的赋值对象

方法

  • apply 实现执行处理
  • compose 构建一个新的Function, 将before的输出作为新Function的apply的输入,新apply的实现同当前
  • andThen 同理
  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2020 Kfdykme
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

支付宝
微信