我看到一段Scala代码,其 list 语法如下。我不知道 WireFormat 在这里意味着什么。它给 list A 添加了什么约束?这是否意味着类型 A 必须扩展特征 WireFormat?
我找不到任何有关此类语法的文档。
trait WireFormat[A] {
def toWire(x: A, out: DataOutput)
def fromWire(in: DataInput): A
}
class DList[A : Manifest : WireFormat]
最佳答案
这是一个context bound 。两种类型用冒号分隔,仅意味着有两个隐式参数。
换句话说,它与以下内容相同:
class DList[A](implicit x: Manifest[A], y: WireFormat[A])
关于scala - 不清楚的 Scala list 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9961463/