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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -