5
Sono sicuro che la risposta è abbastanza semplice, ma mi sono bloccato in questo:puzzle di varargs?
Welcome to Scala version 2.7.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_14).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def f(x:Int*)=0
f: (Int*)Int
scala> val xs:Seq[Int]=1::2::3::4::Nil
xs: Seq[Int] = List(1, 2, 3, 4)
scala> f (xs)
<console>:7: error: type mismatch;
found : Seq[Int]
required: Int
f (xs)
^
Come costruire un 'int *'?
sì! funziona! ... sembra un po 'come "forzare" il tipo, anche se – GClaramunt
Beh, sta forzando il tipo. Il tipo corretto è un elenco di argomenti, non un argomento che è un elenco. A proposito, funziona per qualsiasi tipo di sequenza, così come per qualsiasi tipo che può essere convertito in una sequenza, così potresti aver passato 'List' direttamente. Inoltre, è simmetrico. Si potrebbe fare 'xs match {case List (ys @ _ *) => ...}'. –