user1169587 :
Method reference to instance method from instance
// compile successfully, out is instance, println is instance method
Consumer<String> c = System.out::println;
Method reference to instance method from class type
// compile fail, PrintStream is class type, println is instance method
Consumer<String> c = PrintStream::println;
why Consumer<String> c = PrintStream::println
fail?
Bohemian :
But!
BiConsumer<PrintStream, String> c = PrintStream::println; // compiles!
Method references to the class have an implicit first parameter of the instance. This is similar to Method
whose invoke()
method’s first parameter is the instance.