Java 8:函数引用


#Java 8


示例

定义函数式接口如下:

@FunctionalInterface
public interface IProcessor<T> {

    void process(T t);

}

使用 lambda:

public class Main {

    public static void main(String[] args) {
        IProcessor<Long> processor = aLong -> {
            System.out.println(aLong);
        };
        processor.process(123L);
    }

}

使用 lambda + 函数引用:

public class Main {

    public static void main(String[] args) {
        IProcessor<Long> processor = System.out::println;
        processor.process(123L);
    }

}


( 本文完 )