小编Ahm*_*ker的帖子

Kotlin中的stackoverflowerror

我是kotlin的新手,我的代码有问题:我不知道为什么当我创建类的实例时却给了我stackoverflow错误

这是代码:

class Spice(val spiceName: String,val spiciness: String = "mild") {

    init {
        println("[$spiceName - $spiciness] ")
    }

    val spiceList: List<Spice> = listOf(
            Spice("curry", "mild"),
            Spice("pepper", "medium"),
            Spice("cayenne", "spicy"),
            Spice("ginger", "mild"),
            Spice("red curry", "medium"),
            Spice("green curry", "mild"),
            Spice("hot pepper", "extremely spicy"))

    val heat: Int
        get() {
            return when (spiciness) {
                "mild" -> 1
                "medium" -> 3
                "spicy" -> 5
                "very spicy" -> 7
                "extremely spicy" -> 10
                else -> 0
            }
        }


    fun makeSalt() = Spice("Salt")

}
Run Code Online (Sandbox Code Playgroud)

stack-overflow kotlin

1
推荐指数
1
解决办法
68
查看次数

标签 统计

kotlin ×1

stack-overflow ×1