logo      
Custom Search

Re: Maps in scala

Date: December 28, 2006
From: Eric Willigers <ewilligers@xxxxxxxxx>

In-reply-to: <8071592.post@xxxxxxxxxxxxxxx>
References: <001301c7001f$e255abc0$9801a8c0@Dave> <20061104155919.GM32434@xxxxxxxxxxxxxxxx> <001001c7002e$049b4a10$9801a8c0@Dave> <000c01c70041$11054220$0100000a@Dave510m> <20061104185424.GN32434@xxxxxxxxxxxxxxxx> <e6c6cc500611071858w5a76feebt393c28ed1e27058d@xxxxxxxxxxxxxx> <20061108045711.GD856@xxxxxxxxxxxxxxxx> <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.





Custom Search
home | non blog view