I have a Kotlin enum with multiple fields. One of these fields (enterableBoard) is the value of another enum. At runtime, this val is null despite being set.
I've never seen something like this before, and other fields are working fine, even the one referencing the current Item! I've included the full enum definitions, as I'm not sure what is relevant.
Item enum and a value, where enterableBoard is unexpectedly null instead of Board.SPACEX_EARLY_TREES.
enum class Item(
val chain: ItemChain,
val tier: Int,
@StringRes val title: Int,
@DrawableRes val image: Int,
val generatorMaxEnergy: Int = 0,
val enterableBoard: Board? = null,
val mergeBonus: Pair<Item, Int>? = null,
val redeemable: Pair<InfoLong, Int>? = null
) {
TREE_9(ItemChain.TREE, 9, R.string.item_tree9, R.drawable.item_tree9,
generatorMaxEnergy = 50, enterableBoard = Board.SPACEX_EARLY_TREES)
}
Board enum and the relevant value:
enum class Board(
val campaign: Campaign,
@StringRes val title: Int,
@StringRes val description: Int,
@DrawableRes val background: Int,
@DrawableRes val image: Int,
val unlockCost: Int,
val template: List<Item>
) {
SPACEX_EARLY_TREES(Campaign.SPACEX_EARLY, R.string.board_spacex_early_tree_title, R.string.board_spacex_early_tree_description,
R.drawable.background5, R.drawable.background5, 0,
listOf(Item.FRUITVEG_1, Item.FRUITVEG_2, Item.FRUITVEG_1))
}
Here's a screenshot of enterableBoard being unexpectedly null:
Additional notes:
- I've tried changing other values in
TREE_9, and they all update, so the definition included is definitely the one being used. - The field is also null when trying to access it in code.
- Kotlin version 1.5.20.
- Android Studio 2020.3.1 Patch 1.
