If you're using more than one class from the collections library, or might, import the packages themselves, like so:
import scala.collection.immutable
import scala.collection.mutable
They can then be unambiguously used throughout:
val cache = new mutable.HashMap[String, String]
What say ye?
2 comments:
the language already supports some flexibility on imports:
renaming:
import scala.collection.mutable.{Map => MutableMap}
and then:
var m = new MutableMap[String,String]
or, skip the import statement altogether. since 'scala' is optional when you explicitly refer to a class, you get this:
var h = new collection.mutable.HashMap[String, String]
but, i certainly see your point of legalizing partial path of the package specifier into the usage, if it makes the code intention more clear.
you can also make the case that scala has many duelisms between OO and FP, that are uncommon in traditional languages, and every bit of free "compiler proof" and bonus intention specification should be taken advantage of in solutions dealing with mixed metaphors.
I was under the impression that people had already largely standardised on doing this. It's certainly what I do.
Well, actually I do import collection._, as that makes Map, etc. point to collection.Map rather than immutable.Map as they do by default from the predef.
Post a Comment