What the difference between List.empty
, List()
and new List()
? When should I use which?
From the source code of List we have:
object List extends SeqFactory[List] {
...
override def empty[A]: List[A] = Nil
override def apply[A](xs: A*): List[A] = xs.toList
...
}
case object Nil extends List[Nothing] {...}
So we can see that it is exactly the same
For completeness, you can also use Nil
.