zoukankan      html  css  js  c++  java
  • Java Function 接口

    使用示例

    public class Test {
        public static void main(String args[]) {
            Function<Integer, String> f1 = (score)->{
                if(score > 90) {
                    return "666,我滴宝贝!";
                } else {
                    return "死狗,滚!";
                }
            };
            System.out.println(f1.apply(91));
        }
    }
    
    结果:
    666,我滴宝贝!
    

    Function 源码

    package java.util.function;
    import java.util.Objects;
    /**
     * 函数型接口。
     */
    @FunctionalInterface
    public interface Function<T, R> {
        R apply(T t);
    
        default <V> Function<V, R> compose(Function<? super V, ? extends T> before) {
            Objects.requireNonNull(before);
            return (V v) -> apply(before.apply(v));
        }
    
        default <V> Function<T, V> andThen(Function<? super R, ? extends V> after) {
            Objects.requireNonNull(after);
            return (T t) -> after.apply(apply(t));
        }
    
        static <T> Function<T, T> identity() {
            return t -> t;
        }
    }
    
  • 相关阅读:
    WC命令
    dcoker machine
    linux命令
    Valgrind 检测程序内存使用
    golang flag
    面试之---二叉树的遍历
    FFMpeg 版本错误
    C++中namespace的使用
    QT之QStatusBar
    建立ftp服务器和客户端
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/15223354.html
Copyright © 2011-2022 走看看