表达式`new ListBuffer.empty [Int]`有什么问题

时间:2015-05-12 02:31:19

标签: scala collections

我发现这很有效:

val buf = scala.collection.mutable.ListBuffer.empty[Int]

但是,这不起作用:

import scala.collection.mutable.ListBuffer
val buf = new ListBuffer.empty[Int]

编译器抱怨:

Error:(2, 32) type empty is not a member of object scala.collection.mutable.ListBuffer
lazy val buf = new ListBuffer.empty[Int]
                              ^

有没有人有这方面的想法?

1 个答案:

答案 0 :(得分:4)

ListBuffer.empty不是构造函数,它只是一个返回空ListBuffer的函数。

不需要new关键字。

相关问题