java8--方法引用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jasnet_u/article/details/83475039

方法引用有助于自己的名字指向方法。方法参考描述使用“::”符号。一种方法参考可以用来指向下列类型的方法。

  • 静态方法。

  • 实例方法。

  • 使用new运算符构造函数(TreeSet::new)

例如 :


/**
 * 方法引用
 * @author jelly
 *
 */
public class MethodRefTest {
   public static void main(String[] args) {

 List list=new ArrayList();
  list.add("张小明");
  list.add("李小华");
  list.add("王小虎");
  //list.forEach(s->System.out.println(s));
  //Consumer consumer = s->System.out.println(s);
  //list.forEach(consumer);
  
  list.forEach(System.out::println);
  
  }
}

猜你喜欢

转载自blog.csdn.net/jasnet_u/article/details/83475039