Scala:重载方法解析

Scala:重载方法解析,scala,overloading,Scala,Overloading,Scala的重载方法解析在这里似乎很奇怪: abstract class Parent { type T } class Child extends Parent { type T = Int } def f[T <: Parent](a: Array[T]): Array[T#T] = null def f[T](a: T): Array[T] = null val s = f(Array(new Child)) // OK; calls the

Scala的重载方法解析在这里似乎很奇怪:

abstract class Parent { type T }
class Child extends Parent { type T = Int }

def f[T <: Parent](a: Array[T]): Array[T#T] = null
def f[T](a: T): Array[T] = null

val s = f(Array(new Child))                   // OK; calls the first f
val t: Array[Child#T] = f(Array(new Child))   // type mismatch; tries to apply the second f
抽象类父{type T}
类子级扩展父级{type T=Int}

def f[T这对我来说似乎是个bug。你应该在scala邮件列表上问这个问题。你应该阅读这篇关于为什么要避免方法重载的文章:特别是这篇文章中提到的这篇文章说明了你的问题: