I am trying to learn scala. In one of his lectures, when Martin Odersky talks about Function objects, he talks about how scala functions are expanded to a AnonFun
class that implements FunctionN
(where 1<=N<=22) trait with an apply
method. As an example, he explains that the Anonymous function (x: Int) => x * x is
gets expanded as the following class
new Function1[Int, Int] {
def apply(x: Int) = x * x
}
new AnonFun
So my question is, why does Function1
take generic type [Int, Int]
. Shouldn't one suffice?