The idea of the unbound receiver such as String::length
is you’re referring to a method of an object that will be supplied as one of the lambda’s parameters. For example, the lambda expression (String s) -> s.toUpperCase()
can be rewritten as String::toUpperCase
.
But bounded refers to a situation when you’re calling a method in a
lambda to an external object that already exists. For example, the lambda expression () -> expensiveTransaction.getValue()
can be rewritten as expensiveTransaction::getValue
.
Situations for three different ways of method reference
-
(args) -> ClassName.staticMethod(args)
can beClassName::staticMethod
// This is static (you can think as unBound also) -
(arg0, rest) -> arg0.instanceMethod(rest)
can beClassName::instanceMethod
(arg0
is of typeClassName
) // This is unbound -
(args) -> expr.instanceMethod(args)
can beexpr::instanceMethod
// This is bound
Answer retrieved from Java 8 in Action book