therealbluepandabear
03/20/2021, 3:18 AMclass LootBox(item: Any) {
private var loot = item
}
Instead of
class LootBox<T>(item: T) {
private var loot: T = item
}
Matt Rea
03/20/2021, 3:47 AMclass LootBox<T>(item: T) {
var loot: T = item
}
val lootBox = LootBox("gold”)
val loot: String = lootBox.loot
vs
val lootBox = LootBox(“gold”)
val loot: String = lootBox.loot as String
The latter is unsafe, could cause a crash if T is not a String. The whole idea is to allow LootBox to work with whatever type you want. And allowing users of LootBox to know what type it containstherealbluepandabear
03/20/2021, 3:48 AMMatt Rea
03/20/2021, 3:48 AMtherealbluepandabear
03/20/2021, 3:50 AMMatt Rea
03/20/2021, 4:07 AMtherealbluepandabear
03/20/2021, 4:11 AMgildor
03/23/2021, 3:50 AMtherealbluepandabear
03/23/2021, 3:51 AM