A mistake in a code snippet under the section Generic Constraints


#1

The original code

 val lootBox: LootBox<Loot> = LootBox(Fedora("a dazzling fuschia fedora", 15))
 val fedora: Fedora = lootBox.item // Type mismatch - Required: Fedora, Found: Loot

It should be

val lootBox: LootBox<Loot> = LootBox(Fedora("a dazzling fuschia fedora", 15))
val fedora: Fedora? = lootBox.fetch() // Type mismatch - Required: Fedora, Found: Loot

The parameter item is not declared as either val or var in the primary constructor of LootBox, therefore not accessible on any instances of the class.