When you add a key-value pair to a map: treasureMap += (2 -> "Dig.") , what is 1 -> "Dig." really?
Answer
It is a method call (1).->("Dig") which returns a tuple containing key and value
Tags
#odersky-programming-in-scala-1ed #scala
Question
When you add a key-value pair to a map: treasureMap += (2 -> "Dig.") , what is 1 -> "Dig." really?
Answer
?
Tags
#odersky-programming-in-scala-1ed #scala
Question
When you add a key-value pair to a map: treasureMap += (2 -> "Dig.") , what is 1 -> "Dig." really?
Answer
It is a method call (1).->("Dig") which returns a tuple containing key and value
If you want to change selection, open document below and click on "Move attachment"
Next Steps in Scala ap is empty because you pass nothing to the factory method (the parentheses
in "Map[Int, String]()" are empty).[7]
On the next three lines you add key/value pairs to the map using
the -> and += methods. As illustrated previously, <span>the Scala compiler transforms a binary operation expression like
1 -> "Go to island." into (1).->("Go to island."). Thus, when you say 1 -> "Go to island.", you are actually calling a method
named -> on
an integer with the value 1, passing in a string with the value "Go to island."
This -> method, which you can invoke on any object in a Scala program,
returns a two-element tuple containing the key and value.[8]
You then pass this tuple to the += method of the map
object to which treasureMap refers.
Finally, the last line prints the value that corresponds to the key 2 in the treasureMap. If
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.