I have a map of Int->Queue, and I'm adding to the queues one entry at a time. At the end of the process I need to iterate over the keys and values (because I want to convert the Queues to Arrays), but scala says there are no keys/values in the map. Some simplified code below for illustration purposes. What is going on here? The result of m(4) below is also puzzling.
import scala.collection.mutable.Queue
val m = Map[Int, Queue[Int]]().withDefaultValue(Queue[Int]())
m(1) += 10
res25: scala.collection.mutable.Queue[Int] = Queue(10)
m(1) += 10
res26: scala.collection.mutable.Queue[Int] = Queue(10, 10)
m(1)
res35: scala.collection.mutable.Queue[Int] = Queue(10, 10)
m(4)
res37: scala.collection.mutable.Queue[Int] = Queue(10, 10)
m.keys
res28: Iterable[Int] = Set()
m
res36: scala.collection.immutable.Map[Int,scala.collection.mutable.Queue[Int]] = Map()
Using scala 2.10.3.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…