What does `:_*` (colon underscore star) do in Scala?

前端 未结 4 1836
悲&欢浪女
悲&欢浪女 2020-11-22 06:24

I have the following piece of code from this question:

def addChild(n: Node, newChild: Node) = n match {
  case Elem(prefix, label, attribs, scope, child @ _         


        
4条回答
  •  执笔经年
    2020-11-22 06:46

    • child ++ newChild - sequence
    • : - type ascription, a hint that helps compiler to understand, what type does that expression have
    • _* - placeholder accepting any value + vararg operator

    child ++ newChild : _* expands Seq[Node] to Node* (tells the compiler that we're rather working with a varargs, than a sequence). Particularly useful for the methods that can accept only varargs.

提交回复
热议问题