KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Coming from a Java background, I'm used to the common practice of dealing with collections: obviously there would be exceptions but usually code would look like: public class MyClass { private Set<String> mySet; public void init() { Set<String> s = new LinkedHashSet<String>(); s.add("Hello"); s.add("World"); mySet = Collections.unmodifiableSet(s); } } I have to confess that I'm a bit befuddled by the plethora of options in Scala. There is: scala.List (and Seq ) scala.collections.Set (and Map ) scala.collection.immutable.Set (and Map , Stack but not List ) scala.collection.mutable.Set (and Map , Buffer but not List ) scala.collection.jcl So questions! Why are List and Seq defined in package scala and not scala.collection (even though implementations of Seq are in the collection sub-packages)? What is the standard mechanism for initializing a collection and then freezing it (which in Java is achieved by wrapping in an unmodifiable )? Why are some collection types (e.g. MultiMap ) only defined as mutable? (There is no immutable MultiMap )? I've read Daniel Spiewak's excellent series on scala collections and am still puzzled by how one would actually use them in practice. The following seems slightly unwieldy due to the enforced full package declarations: class MyScala { var mySet: scala.collection.Set[String] = null def init(): Unit = { val s = scala.co
Tags (comma-separated)
Save Edits
Cancel