The Artima Developer Community
Sponsored Link

Programming in Scala Forum
Mutable Map +=

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Xiao Yang

Posts: 3
Nickname: xiao
Registered: Aug, 2011

Mutable Map += Posted: Sep 17, 2011 5:05 PM
Reply to this message Reply
Advertisement
Hi,

On page 392:

import scala.collection.mutable.Map // only change needed!
var capital = Map("US" -> "Washington", "France" -> "Paris")
capital += ("Japan" -> "Tokyo")
println(capital("France"))

Should it work after changing var to val as the object which capital is referring to is mutable? It works if I replace the third line by capital + ("Japan" -> "Tokyo").

Thank you.
Xiao

Topic: Ordered[People] on page 445 should be Ordered[Person] Previous Topic   Next Topic Topic: Second Edition Upgrade Pricing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use