1.creating, initializing, and using an immutable set:
var jetSet = Set("Boeing", "Airbus")
jetSet += "Lear"
println(jetSet.contains("Cessna"))
2.creating, initializing, and using a mutable set:
import scala.collection.mutable.set
val movieSet = Set("Hitch", "Poltergeist")
movieSet += "Shrek"
println(movieSet)
Because the set in 2 is mutable, there is no need to reassign movieSet,
which is why it can be a val. By contrast, using += with the immutable set
in 1 required reassigning jetSet, which is why it must be a var.
Scala's mutable, immutable object
Apr232010
Subscribe to:
Post Comments (Atom)
0 评论: (+add yours?)
Post a Comment