diff --git a/s-day07/src/com/inmind/functional_function06/Demo11.java b/s-day07/src/com/inmind/functional_function06/Demo11.java new file mode 100644 index 0000000..1e885e2 --- /dev/null +++ b/s-day07/src/com/inmind/functional_function06/Demo11.java @@ -0,0 +1,32 @@ +package com.inmind.functional_function06; + +import java.util.function.Function; + +/* +常用的函数式接口-Function,Function就是一个数据工厂,用来进行数据转换 + Interface Function + + 参数类型 + T - 原料的类型 - 参数 + R - 产品的类型 - 返回值 + + 抽象方法: + R apply(T t):表示进T类型的数据转换成R类型的数据 + + 默认方法: + default Function andThen(Function after) 合并2个Function接口,生成一个新的,先执行this的apply方法,再执行after的apply方法 + default Function compose(Function before) 与以上的方法完全相反 + + 需求:"100"->100 + */ +public class Demo11 { + public static void main(String[] args) { +// method(s->{return Integer.parseInt(s);},"100"); + method(s->Integer.parseInt(s),"100"); + } + + public static void method(Function function, String s) { + Integer result = function.apply(s); + System.out.println("结果:"+ result); + } +}