It "splats"1 the sequence.
查看构造函数签名
new Elem(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding,
child: Node*)
这被称为
new Elem(prefix, label, attributes, scope,
child1, child2, ... childN)
但这里只有一个序列,没有child1
, child2
等等,因此这允许将结果序列用作构造函数的输入。
1 This doesn't have a cutesy-name in the SLS, but here are the details. The important thing to get is that it changes how Scala binds the arguments to the method with repeated parameters (as denoted with Node*
above).
The _*
类型注释SLS 的“4.6.2 重复参数”中有介绍。
参数部分的最后一个值参数可以带有“*”后缀,例如(..., x:T)。方法内这种重复参数的类型是
序列类型 scala.Seq[T]。具有重复参数的方法 T * take
类型 T 的可变数量的参数。也就是说,如果方法 m 的类型为
(p1:T1,...,pn:Tn,ps:S)U 应用于参数 (e1, ..., ek),其中 k >= n,则
m 在该应用中被视为具有类型 (p1 : T1, ..., pn : Tn,ps : S, ..., ps0S)U,
其中 k ¡ n 次出现类型 S,其中 ps 之外的任何参数名称都是
新鲜的。此规则的唯一例外是如果最后一个参数被标记为
通过 _ 的序列参数类型注释。如果上面的 m 应用于参数 (e1, . . . , en,e0 : _),那么该应用程序中 m 的类型被视为
(p1:T1,...,pn:Tn,ps:scala.Seq[S])**