Method References
Methods can be passed as arguments for functions. These are not actual method references, but more an auto mapping feature, which wraps methods into an interface implementation.
Lets suppose we have these methods:
It is possible using onRead as the strategy argument:
The read method only needs to call the strategy, and then it will make use of the onRead method, making these two operations equivalent:
Constructor References
Constructors can be passed as arguments too.
Not the constructor can be used as a Function:
Which is the same as:
Static Method References
The same thing can be done with static methods:
Last updated
Was this helpful?