I want to define a simple lambda, add three integers:
(int a, int b,int c)->a+b+c
For this simple case, I have two options:
Define a functional interface. The only abstract method should be int add(int a, int b,int c) , method names and variable names do not matter.
Use the link to the method. 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 simplest lambda, I need to return to the world of OOP (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
source share