I want to define a simple lambda, add up three integers:
(int a, int b,int c)->a+b+c
For this simple case, I have two options:
Define a functional interface. The single abstract method should be
int add(int a, int b,int c)
, the method name and varable names don't matter.Use method reference. I have to define a class/method or use an existing method that has the signature
int add(int a, int b,int c)
In both cases, for the very simple lambda, I have to get back to the OOP world(interface, class, etc)
But in scala, it is very simple to define a function in place:
val add= (a:Int,b:Int,c:Int)=>a+b+c