什么<:<斯卡拉意味着什么?

时间:2012-01-11 13:03:09

标签: scala

  

可能重复:
  What do <:<, <%<, and =:= mean in Scala 2.8, and where are they documented?

e.g。在这个例子中,来自scala-arm 1.0:

def toTraversable[B](implicit ev: R <:< TraversableOnce[B]): Traversable[B] = 
  new ManagedTraversable[B,R] {
    val resource = self
    override protected def internalForeach[U](resource: R, g : B => U) : Unit = 
      ev(resource).foreach(g) 
  }

1 个答案:

答案 0 :(得分:4)

&LT;:其中(以及类似奇怪的构造)在Predef.scala(scala-lang.org中的源代码)中定义,这可能是解决它们的最佳资源。

通常,类似的类可用于在特定方法范围内提供类型参数的进一步限制。 &LT;:其中特别用于要求RTraversableOnce[B]的子类型。

Predef的描述是:

  

约束方法中范围内的任何抽象类型T.   参数列表(不仅仅是方法自己的类型参数)简单   添加类型为T <:< U的隐式参数,其中U是必需的   上限;或者对于下限,使用:L <:< T,其中L是   要求下限。

相关问题