The compiler does see a difference between them, it is just not allowed to use this difference in overloading (since erasures of Some[(Int, String) => Unit]
and Some[Int => Unit]
are the same and JVM doesn't allow overloading when erasures of arguments are the same). The solution is to add fake implicit arguments:
class Foo() {
def fooSome(block: Some[(Int, String) => Unit]) = {
}
def fooSome(block: Some[Int => Unit])(implicit d: DummyImplicit) = {
}
}
Also note that erasures of fooNoSome
are fooNoSome(Function2)
and fooNoSome(Function1)
, so if you wanted to add another overload which takes any function of one or two arguments, you'd need the DummyImplicit
trick again:
def fooNoSome(block: Double => Unit)(implicit d: DummyImplicit) = ...