Consider the below code where I am passing a method and a function as a parameter to map()
val list1:List[Int]=List(10,20,30)
def func1(x:Int):Int={
x+10
}
list1.map(func1)
list1.map(_+10)
I have few questions about ETA expansion:
- Is there a performance difference in using a method in place of a function, especially since the method is internally getting converted into a function?
- Is there a performance difference between
def x:Int=10
andval x:Int=10
? - I have read that the call-by-name parameter is actually a method which does not accept any parameter. Now, if methods are not objects, how are we using a method as a parameter value?