Java 8 – Lambda & Method reference (Multiple arguments method)

Multiple arguments:

In case of a functional interface whose method has multiple arguments, below example shows how to implement it using lambda or method reference.

This can be done using simple lambda expression where arguments have to be in brackets. Then after lambda symbol i.e. -> you can add the implementation you want.

If you already have some other API or class who has similar implementation as what functional interface needs, then you can simply pass on method reference of that already implemented method to functional interface. With this, whenever method is called on functional interface object it will delegate it to that method reference.

 

 

Output:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *