美文网首页
高级集合——方法引用

高级集合——方法引用

作者: hello高world | 来源:发表于2017-01-10 09:26 被阅读0次

方法引用

  • 1、方法引用类似
    Artist::getName 等同于 artist -> artist.getName()
  • 2、所有可以用lambda的都可以使用方法引用
package org.java8.collector;

import java.util.stream.Stream;

import lombok.Value;

public class MethodRefenceTest {
    public static void main(String[] args) {
        Stream.of(new Artist("haha", true))
        .filter(Artist::isOld)
        .forEach(System.out::println);
    }
    @Value
    static class Artist{
        private final String name;
        private final boolean old;
    }
}

相关文章

网友评论

      本文标题:高级集合——方法引用

      本文链接:https://www.haomeiwen.com/subject/fblkbttx.html