The Artima Developer Community


Errata for Programming in Scala, 2nd Edition
Chapter 29: Modular Programming Using Objects
Return to errata index.

Page 646 (PDF page 680):
In a simple program that chooses a database at runtime, even though we
choose a database based on the input parameter, we later nonchalantly 
discard that choice and hard wire to the "SimpleDatabase":

object GotApples {
  def main(args: Array[String]) {
    val db: Database =
      if(args(0) == "student")
        StudentDatabase
      else
        SimpleDatabase

    object browser extends Browser {
      val database = db
    }

    val apple = SimpleDatabase.foodNamed("Apple").get
                ^
    for (recipe <- browser.recipesUsing(apple))
      println(recipe)
  }
}

The marked line should be:
val apple = db.foodNamed("Apple").get

Page number: Book type: Paperback book PDF eBook
Book version: (Or build date. Found on back of title page.)
Your feedback:
Your name: (optional)
Your email address: (optional) (will not be published)

Copyright © 2021 Artima, Inc. All rights reserved.