代码
提交代码
import java.util.function.Consumer;
public class LambdaDemo3 {
public static void main(String[] args) {
// 单参数无返回值
Consumer<String> consumer1 = new Consumer<String>() {
@Override
public void accept(String s) {
System.out.println(s);
}
};
consumer1.accept("Hello World!");
Consumer<String> consumer2 = (String s) -> {
System.out.println(s);
};
consumer2.accept("你好,世界!");
}
}
运行结果