代码
提交代码
import java.util.function.Consumer;
public class DemoConsumer {
public static void main(String[] args) {
//调用默认方法
consumerString(s -> System.out.println(s));
//consumer接口的组合
consumerString(
// toUpperCase()方法,将字符串转换为大写
s -> System.out.println(s.toUpperCase()),
// toLowerCase()方法,将字符串转换为小写
s -> System.out.println(s.toLowerCase())
);
}
private static void consumerString(Consumer<String> consumer) {
consumer.accept("Hello");
}
private static void consumerString(Consumer<String> first, Consumer<String> second) {
first.andThen(second).accept("Hello");
}
}
运行结果