scala - Why use Collection.empty[T] instead of new Collection[T]() -
scala - Why use Collection.empty[T] instead of new Collection[T]() -
i wondering if there reason utilize collection.empty[t] instead of new collection[t]() (or inverse) ? or personal preference ?
thanks.
calling new collection[t]() create new instance every time. on other hand, collection.empty[t] homecoming same singleton object, defined somewhere as
object empty extends collection[nothing] ... which much faster. edit: possible immutable collections, mutable collections have homecoming new instance every time empty called.
scala
Comments
Post a Comment