What are the practical differences between a function and a method in Scala? I am only trying to build a list of practical differences, which I didn't readily find in the other entry talking about functions and methods in Scala.
So far, I have found that:
- functions cannot have default values for their parameters but methods can,
- functions can be anonymous, but methods always have a name,
- methods can be type-parameterized, but functions can't.
Any other real difference?
Also, what is going on here? The types of both objects seem to be the same?
scala> val f = (x: Int) => x + 1
f: Int => Int = $$Lambda$1097/560897187@75120e58
scala> :t f
Int => Int
scala> def g = (x: Int) => x + 1
g: Int => Int
scala> :t g
Int => Int