方法引用有助于自己的名字指向方法。方法参考描述使用“::”符号。一种方法参考可以用来指向下列类型的方法。
静态方法。
实例方法。
使用new运算符构造函数(TreeSet::new)
例如 :
/**
* 方法引用
* @author jelly
*
*/
public class MethodRefTest {
public static void main(String[] args) {
List
list.add("张小明");
list.add("李小华");
list.add("王小虎");
//list.forEach(s->System.out.println(s));
//Consumer
//list.forEach(consumer);
list.forEach(System.out::println);
}
}
Copyright © 叮叮声的奶酪 版权所有
备案号:鄂ICP备17018671号-1