The problem is that Int => T also a type. For example, let's say you only defined the second beta :
def beta[ T ]( thunk: => T ) : String = thunk.toString
And now you pass it the function Int => Int :
scala> beta((_: Int) + 1) res0: String = <function1>
So, given that the function is suitable for => T , and that you also have Int => T , how should Scala know which one you want? It could be a String , for example:
scala> beta((_: String) + 11) res1: String = <function1>
How does Scala assume that it was Int ? The examples you showed to demonstrate overloading are not to blame, they donβt show anything like that, because you got rid of the type parameters in them.
Daniel C. Sobral
source share