# jdk8 **Repository Path**: mr_sen/jdk8 ## Basic Information - **Project Name**: jdk8 - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-09 - **Last Updated**: 2021-06-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ##一、function接口 >需要接受一个类型的参数,同时返回一个类型的参数。 应用于: 1)对数据的加工:对字符串的大小写转化 2)对传入的数据应用后,同时要返回一定的结构 ```java public interface Function { /** * Applies this function to the given argument. * * @param t the function argument * @return the function result */ R apply(T t); } ``` ##二、Consumer接口 >接受一个参数,无返回值 应用于: 1)集合、数组的遍历 2) ```java @FunctionalInterface public interface Consumer { /** * Performs this operation on the given argument. * * @param t the input argument */ void accept(T t); } ``` ##三、Supplier 接口 >不需要参数,但可以返回数据 这个接口就是给方法确定放回值类型的 应用场景: 1)一个方法不确定返回值类型,就可以设计成 参数为Supplier类型的参数 2)Dao层方法的签名,根据泛型的类型,去数据库查数据并返回 ```java @FunctionalInterface public interface Supplier { /** * Gets a result. * * @return a result */ T get(); } ``` ##四、Predicate >接受一个参数返回一个布尔数据 应用场景: 1)对参数的校验 ```java @FunctionalInterface public interface Predicate { /** * 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); } ``` ## ```java ``` ## ```java ``` ## ```java class ss{ Stream filter(Predicate predicate); default Stream stream() { return StreamSupport.stream(spliterator(), false); } } ```