多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
### 2.2.3 Function Function接收一个T行为,并且返回R,以下是其源码: ```java @FunctionalInterface public interface Function<T, R> { R apply(T t); ``` 下面的例子展示了Function的用法: ```java import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class FunctionTest { public static void main(String[] args) { List<Integer> numberList = new ArrayList<>(); Function<Integer, String> action = (in) -> Integer.toBinaryString(in); List<String> binStringList = filter(numberList, action); } static <T, R> List<R> filter(List<T> list, Function<T, R> action) { List<R> result = new ArrayList<>(list.size()); for (T item : list) { result.add(action.apply(item)); } return result; } } ```