java8新特性Supplier接口的使用与类引用

https://www.cnblogs.com/webor2006/p/8243874.html

注意每次调用get方法,返回的是不同的对象:

public class Main {
    public static void main(String[] args) {
        Supplier<Student> supplier = Student::new;
        System.out.println(supplier.get());
        System.out.println(supplier.get());

    }
}

console:

com.lightbend.akka.demo.Student@7cc355be
com.lightbend.akka.demo.Student@6e8cf4c6

Process finished with exit code 0

另外::不是Supplier专用的,接口范型,构造时都可以。

你可能感兴趣的:(java基础增强)