zoukankan      html  css  js  c++  java
  • 函数式遍程----Function

    Consumer定义

    @FunctionalInterface
    public interface Consumer<T> {
    
        void accept(T t);
    
        default Consumer<T> andThen(Consumer<? super T> after) {
            Objects.requireNonNull(after);
            return (T t) -> { accept(t); after.accept(t); };
        }
    }

    其核心的方法如下:

    void accept(T t){

    }

    default Consumer andThen(Consumer<? super T> after){

    }

    Consumer在处理的时候是没有返回值

    Function<T,R>  

    @FunctionalInterface
    public interface Function<T, R> {
    
        /**
         * Applies this function to the given argument.
         *
         * @param t the function argument
         * @return the function result
         */
        R apply(T t);
    }
    public int compute(int a, Function<Integer, Integer> function) {
        int result = function.apply(a);
        return result;
    }
    test.compute(5,value -> value * value) //25 计算平方
    test.compute(5,value -> value + value) //10 求和
    test.compute(5,value -> value - 2) //3  
  • 相关阅读:
    07 selenium模块基本使用
    06 高性能异步爬虫
    05 request高级操作
    04 验证码识别
    03 数据解析
    02 requests模块
    01 爬虫简介
    Get和Post的正解
    pytoch之 encoder,decoder
    pytorch之 RNN 参数解释
  • 原文地址:https://www.cnblogs.com/dousil/p/12859426.html
Copyright © 2011-2022 走看看