Questions tagged «type-parameter»

1
模式匹配中方法类型推断与类类型参数的区别
当类型参数来自封闭方法而不是封闭类时,为什么模式匹配的工作方式有所不同?例如, trait Base[T] case class Derived(v: Int) extends Base[Int] class Test[A] { def method(arg: Base[A]) = { arg match { case Derived(_) => 42 } } } 给出错误 constructor cannot be instantiated to expected type; found : A$A87.this.Derived required: A$A87.this.Base[A] case Derived(_) => 42 ^ 虽然它成功地编译A为方法类型参数 class Test { def …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.