I learn new features of Java 8.
I am playing with different examples and I have found a strange behaviour:
public static void main(String[] args) {
method(Test::new);
}
static class Test{
}
private static void method(Supplier<Test> testSupplier){
Test test = testSupplier.get();
}
This code compiles successfully but I have no idea how it works.
Why is Test::new
acceptable as Supplier?
Supplier interface looks very simple:
@FunctionalInterface
public interface Supplier<T> {
T get();
}