开发者

varargs parameter as type parameter?

Is there any way to create something similar to this:

class F[A] {def apply(a: A) = println(a)}

So that I can:

(new F[Int*])(开发者_如何学C1,2,3)

UPDATE: but otherwise, I want F to accept normal parameters:

(new F[Int])(1)


scala> class F[A] { def apply(a: A*) = a.length }
defined class F    

scala> val instance = new F[Int]
instance: F[Int] = F@11a6631

scala> instance(1,2,3,4,5)
res4: Int = 5
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜