开发者

varargs parameter as type parameter?

开发者 https://www.devze.com 2023-01-03 11:21 出处:网络
Is there any way to create something similar to this: class F[A] {def apply(a: A) = println(a)} So that I can:

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

精彩评论

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