Custom Search
|
Re: Maps in scala
Date: December 28, 2006
In-reply-to:
<8071592.post@xxxxxxxxxxxxxxx>
steve.bendiola wrote:
>
> I was going to update the wiki with the different ways to access/modify
> maps, but I don't understand why the last line in this code sample fails:
>
> val map = new scala.collection.mutable.HashMap[String, Any]
>
> map("likes") = "cheese"
> assume( map.get("likes") == Some("cheese") )
> assume( map("likes") == "cheese")
>
> assume( map.get("fakeKey") == None)
>
> map += "name" -> "Gromit"
> assume( map("name") == "Gromit")
>
> map += "id" -> 1234
> assume( map.get("id") == Some(1234) )
> assume(map.get("id") == 1234, "map.get(id) == 1234 failed" )
>
Replace the last line with
assume(map("id") == 1234)
This is equivalent to
assume(map.apply("id") == 1234)
map.get("id") returns Some(1234), and Some(1234) != 1234
--
View this message in context:
http://www.nabble.com/Maps-in-scala-tf2573926.html#a8071637
Sent from the Scala mailing list archive at Nabble.com.
|