常用的函数接口

来源:互联网 发布:淘宝详情页的制作 编辑:程序博客网 时间:2024/05/17 01:33

   常用的函数接口:

  

@FunctionalInterfacepublic interface Function<T, R> {    /**     * Applies this function to the given argument.     *     * @param t the function argument     * @return the function result     */    R apply(T t);}
   输入参数T,转换为目标类型R


@FunctionalInterfacepublic interface Predicate<T> {    /**     * Evaluates this predicate on the given argument.     *     * @param t the input argument     * @return {@code true} if the input argument matches the predicate,     * otherwise {@code false}     */    boolean test(T t);}
   输入参数T,返回boolean值,做判断使用


@FunctionalInterfacepublic interface Supplier<T> {    /**     * Gets a result.     *     * @return a result     */    T get();}
   没有输入,返回T类型数据


@FunctionalInterfacepublic interface Consumer<T> {    /**     * Performs this operation on the given argument.     *     * @param t the input argument     */    void accept(T t);}

   输入T类型,没有返回值

     

0 0