Scala for the Impatient 2nd Edition

Bug Report Page


How to Tell which Printing You Have

On the bottom of the copyright page (facing the first page of the table of contents), look for the very last line in the copyright page. It will look like 1 16, 2 17, and so on. The first number is the printing number.
In the errata below, we indicate the printing in which the error has been fixed inside square brackets such as [4].

For example, suppose you have the fourth printing. Then you can ignore all reports that are prefixed with [2], [3] or [4]. But you would want to pay attention to all reports that are prefixed with [5] or higher or that have no bracketed prefix at all.

Page 9 [2]
Change def apply(n: Int): Char to def apply(i: Int): Char
Page 9 [2]
Change “You can use parentheses:” ("Bonjour".sorted)(3) to: “You can use another variable:”
val result = "Bonjour".sorted
Page 22 [2]
Change import to import
Page 35 [2]
Change JavaConversions to JavaConverters
Page 38 [2]
Change 0 until a.length by -1 to a.length -1 to 0 by -1, both above and in the tip.
Page 43 [2]
Change “Instead, import the implicit conversion methods in scala.collection.JavaConversions. Then you can use Scala buffers in your code, and they automatically get wrapped into Java lists when calling a Java method.” to “Instead, import the conversion methods in scala.collection.JavaConverters. Then you can call the asJava method to convert any sequence (such as a Scala buffer) into a Java list.”
Page 44 [2]
Change import scala.collection.JavaConversions.bufferAsJavaList to import scala.collection.JavaConverters._ and val pb = new ProcessBuilder(command) to val pb = new ProcessBuilder(command.asJava)
Page 44 [2]
Change “you can have it automatically converted into a Buffer” to “you can convert it into a Buffer
Page 44 [2]
Change import scala.collection.JavaConversions.asScalaBuffer to import scala.collection.JavaConverters._ and val cmd : Buffer[String] = pb.command() to val cmd : Buffer[String] = pb.command().asScala
Page 49 [2]
In the note, change scores1.get("Zelda") to scores1("Zelda") and scores2.get("Zelda") to scores2("Zelda")
Page 50 [2]
Remove “This is also useful if you want to work with a mutable tree map, which Scala doesn’t provide.”
Page 51 [2]
Change import scala.collection.JavaConversions.mapAsScalaMap to import scala.collection.JavaConverters._, change “Then trigger the conversion by specifying the Scala map type:” to “Then use the asScala method to turn the Java map into a Scala map:”, and change
val scores: scala.collection.mutable.Map[String, Int] =
  new java.util.TreeMap[String, Int]
val ids = java.time.ZoneId.SHORT_IDS.asScala
  // Yields a scala.collection.mutable.Map[String, String]
Page 51 [2]
import scala.collection.JavaConversions.propertiesAsScalaMap
val props: scala.collection.Map[String, String] = System.getProperties()
val props = System.getProperties.asScala
  // Yields a Map[String, String], not a Map[Object, Object]
Page 51 [2]
Change “the opposite implicit conversion” to “the opposite conversion” and change
import scala.collection.JavaConversions.mapAsJavaMap
import java.awt.font.TextAttribute._ // Import keys for map below
val attrs = Map(FAMILY -> "Serif", SIZE -> 12) // A Scala map
val font = new java.awt.Font(attrs) // Expects a Java map
import java.awt.font.TextAttribute._ // Import keys for map below
val attrs = Map(FAMILY -> "Serif", SIZE -> 12) // A Scala map
val font = new java.awt.Font(attrs.asJava) // Expects a Java map
Page 69 Exercise 6 [2]
Change “Section 5.1, “Simple Classes and Parameterless Methods,” on page 55 to ”Section 5.2, “Properties with Getters and Setters” on page 56”
Page 104 [2]
Change f"$time04d" to f"$time%04d"
Page 111 [2]
Change to StdIn.readInt()
Page 172 [2]
In the figure, change SortedSeq to SortedSet
Page 191 [2]
Change “The JavaConversions object” to “The JavaConverters object” and remove “Give the target value an explicit type to trigger the conversion.”
Page 191 [2]
import scala.collection.JavaConversions._
val props: scala.collection.mutable.Map[String, String] = System.getProperties()
import scala.collection.JavaConverters._
val props = System.getProperties.asScala
Page 191 [2]
Change “If you are worried about unwanted implicit conversions, just import the ones you need, for example: import scala.collection.JavaConversions.propertiesAsScalaMap” to:
If you want to have complete control over the target type, use an explicit conversion function:
val propsMap = mapAsScalaMap(System.getProperties)
  // Yields a Map[Object, Object]
Page 191 [2]
Change val props: scala.collection.mutable.Map[String, String] = System.getProperties() to val props = System.getProperties.asScala
Page 192 [2]
In the tables, change “Implicit Function” to “Conversion Function”
Page 204 [2]
Change import scala.collection.JavaConversions.propertiesAsScalaMap to import scala.collection.JavaConverters._ and change System.getProperties() to System.getProperties.asScala (3x)
Page 309
Change “the value is now simply e” to “the value is now simply expr
Page 341 (3x), 342, 343, 344, 345, 348, 350, 351, 355 (2x) [2]
Change JavaConversions to JavaConverters

Thanks to Prashanth Babu, Michael Josephson, Mokhtar Khorshid, Artem Koval, Alex Levin, David Lott, Paul Nelson, Nico Serfontein, Bradley Smith, Clark Verbrugg, and (your name might go here) for their bug reports and suggestions!

Bug Report Form

Please use this form to report any bugs that you find. Please check the list of known bugs first before you report a bug. Unfortunately, I do not have the time to respond personally to every report, but I do read them all and will post updates to this page. Thank you!

Your name:

Your email address:

Page number:

Problem description:

To protect against spam robots, please answer this simple math problem:
* =