在构造函数中调用super并在Kotlin中指定一个字段?

pix*_*xel 2 constructor kotlin

我想status在构造函数中初始化字段而不是调用super.

class MyException : RuntimeException {

    init {
        val status: Status
    }

    constructor(status: Status) : super()

    constructor(status: Status, cause: Throwable) : super(cause)

}
Run Code Online (Sandbox Code Playgroud)

我怎样才能实现这一目标?

vod*_*dan 8

这对我有用:

class MyException : RuntimeException {
    val status: Status

    constructor(status: Status) : super() {
        this.status = status
    }

    constructor(status: Status, cause: Throwable) : super(cause) {
        this.status = status
    }
}
Run Code Online (Sandbox Code Playgroud)