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  
  • 相关阅读:
    Redis
    Maven总结
    spring知识点总结
    网上好文搜集整理
    python 代码删除空目录
    plantUML使用指南
    python的基础操作
    八卦基础编程学习
    python历年入坑记录大全
    python实现的百度云自动下载
  • 原文地址:https://www.cnblogs.com/dousil/p/12859426.html
Copyright © 2011-2022 走看看