将 scala (2.8) 案例类中可变数量的参数传递给父构造函数
我正在尝试 Scala 中案例类的可变构造函数参数,但无法将它们传递给案例类父级的构造函数:
abstract case class Node(val blocks: (Node => Option[Node])*)
case class Root(val elementBlocks: (Node => Option[Node])*) extends Node(elementBlocks)
上面的内容无法编译...实际上可以做到这一点吗?
I was experimenting with variable constructor arguments for case classes in Scala, but am unable to pass them to the constructor of a case classes' parent:
abstract case class Node(val blocks: (Node => Option[Node])*)
case class Root(val elementBlocks: (Node => Option[Node])*) extends Node(elementBlocks)
the above doesn't compile... is it actually possible to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
:_*
语法,这意味着“将此序列视为序列”!否则,您的 n 个项目序列将被视为 1 个项目的序列(这将是您的 n 个项目的序列)。You need to use the
:_*
syntax which means "treat this sequence as a sequence"! Otherwise, your sequence of n items will be treated as a sequence of 1 item (which will be your sequence of n items).这适用于 2.7:
应该适用于 2.8。
This works with 2.7:
Should work with 2.8.