我有一个重载方法定义如下:
def g(f: () ⇒ Double): Object = null
def g(f: Double ⇒ Double): Object = null
def g(f: (Double, Double) ⇒ Double): Object = null
def h(f: (Double, Double) ⇒ Double): Object = null
虽然h(math.max _)
按预期工作,但调用g(math.max _)
给我错误“重载方法......不能应用于((Int,Int)=> Int)”。似乎编译器选择了 Int 版本math.max
而不是 Double 版本。
g
如何以 math.max 作为参数调用我的重载方法?如果我可以在g(math.max)
没有下划线的情况下调用,那将是一个额外的好处。