There is this other question that only explains passing function references but this does not answer the question below on how this Java assignment works, the conversion to this Supplier
object and when this happens.
I have the following code snippet and struggling a bit to understand it and probably I am not the only one. Can someone give a "for dummies" explanation of this code (both the Supplier pattern and the assignment using double-colon (::
) operator. When is Java actually making the function call? My expectation is that objectFactorySupplier
becomes a function pointer.
private Supplier<ObjectFactory> getObjectFactorySupplier(String name) {
// how does this assignment work?
Supplier<ObjectFactory> objectFactorySupplier = this::getObjectFactory;
...
return objectFactorySupplier;
}
private ObjectFactory getObjectFactory() {
ObjectFactory factory = new ObjectFactorySupplier().get();
...
return factory;
}