有没有办法创建类似的东西:
class F[A] {def apply(a: A) = println(a)}
所以我可以:
(new F[Int*])(1,2,3)
更新:但是否则,我希望F接受正常参数:
(new F[Int])(1)
答案 0 :(得分: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