java8_函数式接口

标签:java

函数式接口

  • Supplier<T>接口

    Supplier<Integer> supplier=()->random.nextInt();
    

    Supplier<T>接口,译作供应商,提供一个获取T类型对象的T get()函数

  • Consumer<T>接口

    Consumer<Integer> consumer=integer->System.out.println("deal with "+integer);    
    

    Consumer<T>接口,译作消费者,提供一个处理T类型对象的void accept(T)函数

  • Predicate<T>接口

    Predicate<Integer> predicate=(integer)->integer>0;   
    

    Predicate<T>接口, 译作验证器,提供一个校验T类型对象的boolean test(T)函数

  • To...Function接口

        ToIntFunction<String> toIntFunction=
        (string)->Integer.valueOf(string);
        ToLongFunction<T>
        ToDoubleFunction<T>   
    

    To...Function接口,译作。。类型转换器,提供一个转换T类型对象为指定。。的函数

  • ..Function接口

        IntFunction<String> intFunction=String::valueOf;
        LongFunction<R>
        DoubleFunction<R>  
    

    ..Function接口,提供一个接受R类型对象转换为原始类型的函数

  • Function<T,R>接口

    Function<Integer,String> function=
        integer -> String.valueOf(integer);
    

    Function<T,R>接口,普通函数,提供一个接收T对象,返回R对象

  • BiFunction<T,R,U>

    BiFunction<Integer,Long,String> biFunction=
        (intValue,longValue)->String.valueOf(intValue+longValue);
    

    BiFunction<T,R,U>,提供一个接收T,R对象,返回U对象的函数

  • UnaryOperator接口

    UnaryOperator<Integer> unaryOperator=
        integer -> integer++;
    

    一元操作,继承Function<T>接口

  • BinaryOperator接口

    BinaryOperator<Integer> binaryOperator=
        (integer, integer2) -> integer+integer2;
    

    二元操作,继承BIFunction接口

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容