diff --git a/s-day07/src/com/inmind/functional_interface02/Demo04.java b/s-day07/src/com/inmind/functional_interface02/Demo04.java new file mode 100644 index 0000000..f7cf99c --- /dev/null +++ b/s-day07/src/com/inmind/functional_interface02/Demo04.java @@ -0,0 +1,30 @@ +package com.inmind.functional_interface02; + +import java.util.function.Consumer; + +/* +在jdk中,提供了一些常用的函数式接口供开发人员使用 +常用的函数式接口_Consumer +void accept(T t) 对给定的参数执行此操作。 + +注意: + 1.Consumer表示的是一个消费,只接收参数,没有返回值 + 2.什么时候要使用Consumer的接口?? + 当我们程序员,要定义一个函数式接口,接口中的方法只接收一个参数,没有返回值的方法,直接使用Consumer + + 需求:定义出一个使用常用函数式接口Consumer作为参数,并对字符串进行消费操作的方法(大写打印,小写打印) + */ +public class Demo04 { + public static void main(String[] args) { + String str = "aBcAbC"; + method((String s)->{ + System.out.println(s.toUpperCase()); + },str); + + } + + //定义一个Consumer,String作为参数的方法,消费操作:大写(小写)打印操作 + public static void method(Consumer consumer, String str) { + consumer.accept(str); + } +}