Scala编程语言:1)Var不可变Map、Val可变Map和Var可变Map有什么区别?
Scala编程语言:1)Var不可变Map、Val可变Map和Var可变Map有什么区别?
这个问题的答案已经在这里了:
Var不可变Map、Val可变Map和Var可变Map之间的区别是什么?
此外,为什么所有这些Map的定义都表现得好像它们是可变的?
scala> var var_m_map = collection.mutable.Map(("key1",1), ("key2",2)) var_m_map: scala.collection.mutable.Map[String,Int] = Map(key2 -> 2, key1 -> 1) scala> var_m_map += ("key30" -> 30) res8: scala.collection.mutable.Map[String,Int] = Map(key30 -> 30, key2 -> 2, key1 -> 1) scala> val val_m_map = collection.mutable.Map(("key10",10), ("key20",20)) val_m_map: scala.collection.mutable.Map[String,Int] = Map(key20 -> 20, key10 -> 10) scala> var_m_map += ("key30" -> 30) res9: scala.collection.mutable.Map[String,Int] = Map(key30 -> 30, key2 -> 2, key1 -> 1) scala> var var_i_map = collection.immutable.Map(("key100",100), ("key200",200)) var_i_map: scala.collection.immutable.Map[String,Int] = Map(key100 -> 100, key200 -> 200) scala> var_i_map += ("key300" -> 300) scala> var_i_map res11: scala.collection.immutable.Map[String,Int] = Map(key100 -> 100, key200 -> 200, key300 -> 300) scala> var var_i_map2 = Map(("key700",700), ("key800",800)) var_i_map2: scala.collection.immutable.Map[String,Int] = Map(key700 -> 700, key800 -> 800) scala> var_i_map2 += ("key900" -> 900) scala> var_i_map2 res13: scala.collection.immutable.Map[String,Int] = Map(key700 -> 700, key800 -> 800, key900 -> 900)
admin 更改状态以发布 2023年5月23日