@FunctionalInterfacepublicinterfaceFunction<T,R>{/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return R the function result
*/Rapply(T t);}
函数式接口可以用Lambda表达式简化;
/** Function 函数型接口,有一个输入参数,有一个输出;*/Function function =newFunction<String,String>(){@OverridepublicStringapply(String o){return o;}};System.out.println(function.apply("788"));/** 断定型接口:有一个输入参数,返回值只能是布尔值!*/Predicate<String> predicate =newPredicate<String>(){@Overridepublicbooleantest(String s){returnfalse;}};System.out.println(predicate.test("7"));/** Consumer 消费型接口:只有输入,没有返回值 */Consumer<String> consumer =newConsumer<String>(){/**
* Performs this operation on the given argument.
* @param o the input argument
*/@Overridepublicvoidaccept(String o){System.out.println(o);}};
consumer.accept("7889");/** Supplier供给型接口没有参数,只有返回值 */Supplier<String> supplier =newSupplier<String>(){@OverridepublicStringget(){return"123456";}};System.out.println(supplier.get());
函数式接口/** *程序员必备技术:lambda表达式、链式编程、函数式接口、Stream流式计算 *函数式接口:只有一个方法的接口; *只要是函数型接口可以用Lambda表达式简化;*/@FunctionalInterfacepublic interface Function<T, R> { /** * Applies this function to the given argument. * * @param t the functi