💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 2.2.2 Consumer Consumer接收一个T行为,并且没有返回值,以下是其源码: ```java @FunctionalInterface public interface Consumer<T> { void accept(T t); } ``` 下面的例子展示了Consumer的用法: ```java import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; public class ConsumerTest { public static void main(String[] args) { List<Integer> numberList = new ArrayList<>(); Consumer<Integer> action = c -> System.out.println(c); filter(numberList, action); } static <T> void filter(List<T> list, Consumer<T> action) { for (T item : list) { action.accept(item); } } } ```