💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 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; } } ```