表达式 new ListBuffer.empty[Int] 有什么问题
What's wrong with the expression `new ListBuffer.empty[Int]`
我发现这个效果很好:
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]
^
有人对此有想法吗?
ListBuffer.empty
不是构造函数,它只是一个 returns 空 ListBuffer 的函数。
不需要 new
关键字。
我发现这个效果很好:
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]
^
有人对此有想法吗?
ListBuffer.empty
不是构造函数,它只是一个 returns 空 ListBuffer 的函数。
不需要 new
关键字。