[英]In Scala, How to define a class method that only takes subclass-type argument?
我试过了
def function[T <: this.type](parameter: T)
但这不起作用。
这应该只是一个简单的问题,它的权重太大,无法在使用该函数之前定义CanBuildFrom并每次将其导入
标准集合使用类型参数对其进行编码。
scala> abstract class X[Repr <: X[Repr]] { def f(r: Repr) }
defined class X
scala> class Y extends X[Y] { def f(y: Y) = ??? }
defined class Y
scala> val y = new Y
y: Y = Y@6ae40994
scala> y f y
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:225)
at Y.f(<console>:8)
... 33 elided
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.