Double Colon lambda for two levels method invocation

Viewed 708

Is there a way to use doubleColon to invoke second level method. Example ClassA::getClassBObject::classBMethod in lambda invocation

2 Answers

What you are expecting is called chaining. Method references does not support chaining.

Read more about Method References.

You could compose the functions:

((Function<ClassA, ClassB>) ClassA::getClassBObject).andThen(ClassB::classBMethod)

But you're probably better off with just (x, arg) -> x.getClassBObject().classBMethod(arg).

More info on the composition approach: https://stackoverflow.com/a/32838924/2093695

Related