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;
        }
    }
    
  • 相关阅读:
    Oracle数据库基础
    2016-08-08二期模拟考试
    易买网-登入
    常量接口模式
    反射
    Hhibernate延迟加载
    URL和URI的区别和联系
    Socket编程
    ArrayList如何实现线程安全
    移位运算符
  • 原文地址:https://www.cnblogs.com/feiqiangsheng/p/15223354.html
Copyright © 2011-2022 走看看