Kotlin Coroutine Confidence: Book & source code do not match (pg 180)

On page 180 it says:

If you’re a fan of fluffy felines, you’ll be starting here.
pets/v1/src/main/kotlin/com/example/pets/PetService.kt
const val url = "https://api.thecatapi.com/v1/"
Or, if you’re all about those cuddly canine companions, just swap that line
for this one.
pets/v1/src/main/kotlin/com/example/pets/PetService.kt
const val url = "https://api.thedogapi.com/v1/"

However, the source code has two objects:

object Cats {
  const val url = "https://api.thecatapi.com/v1/"
}

object Dogs {
  const val url = "https://api.thedogapi.com/v1/"
}

with the URL that is used being decided by the import in the file:

import com.example.pets.Dogs.url

So you’ll likely want to update the text on pg 180 to indicate you make the change by changing the import.

p.s. Cats are OK, but Dogs Rule! :dog_face:

book-kotlin-coroutine-confidence version B3

Thanks, that’s useful feedback. As you probably guessed, using the two object declarations was a convenient way to include both URLs in the same source file without having a name clash. But I agree that it’s a little confusing, since it means the code in the downloaded source file doesn’t exactly match what I’m describing in the book. I’ll see what I can do to improve that. Adding a note in the text, as you suggested, sounds like a simple solution.

1 Like