Custom Search
|
Re: Maps in scala
Date: December 28, 2006
In-reply-to:
<20061108045711.GD856@xxxxxxxxxxxxxxxx>
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" )
Jamie Webb wrote:
>
> On Tue, Nov 07, 2006 at 08:58:56PM -0600, John Williams wrote:
>> This is good stuff! It's perfectly obvious once you see it, but it
>> would have taken me forever to think of this on my own. Has anyone
>> made a collection of tips like this somewhere? I think such a
>> collection would be a big help to Scala programmers who are trying to
>> move beyond writing Java-like code.
>
> The Wiki at scala.sygneca.com has various code examples, but they tend
> to be longer.
>
> Trouble is, personally I would have trouble identifying 'tips' unless
> I'm asked a question. Maybe someone could start a 'most hated Java
> idioms' page and we'll see how Scala fares...
>
> -- Jamie Webb
>
>
--
View this message in context:
http://www.nabble.com/Maps-in-scala-tf2573926.html#a8071592
Sent from the Scala mailing list archive at Nabble.com.
|