Errata for Kotlin Apprentice 2nd Edition

Creating this topic to catch any typos and bugs in the 2nd Edition of Kotlin Apprentice.

Just going through the 2nd Edition now.
Chapter 4 - pg 89.

The paragraph near the bottom:
“Since 1 < 2 is true, the whole expression must be true as well. Therefore once again, the check of name is not executed. This will come in handy later on when you start dealing with more complex data types.”

This paragraph needs to be removed. It is from the preceding page (88), and somehow was duplicated here.

Thanks @chuck_taylor! We’ve logged this errata and will fix in our next update.

Kudos for writing a great book on Kotlin.

On page 238 of 2nd Edition, I see an issue. Should the size function be written as (written this fun inside the Shape class

   fun size(): Int {
		return when (this) {
			is Shape.Circle -> this.radius
			is Shape.Square -> this.sideLength


page 68, the 2nd line: …naïve way to attempt
page 71, the 2nd line from the bottom: …using the naïve operation…

Thanks for the question @pgudivada!

As written in the book, the size() function is not meant to be a method on the Shape enum class, it’s just a stand-alone function. So you would call it like this:


Thanks again for the question!

Thanks for catching that @martin.kubik! We’ve logged the issue and will fix in the next edition.

1 Like

We have the following paragraph in the book:

As with any type, it’s good practice to declare arrays that aren’t going to change as
constants using val. For example, consider this array:

val vowels = arrayOf("a", "e", "i", "o", "u")

vowels is an array of strings and its values can’t be changed. But that’s fine, since
the list of vowels doesn’t tend to change very often!

Edition 2, chapter 8, page 136

though it’s not the array values are not going to change, it’s the reference to the Array.