除了调用status
之外,我想在构造函数中初始化super
字段。
class MyException : RuntimeException {
init {
val status: Status
}
constructor(status: Status) : super()
constructor(status: Status, cause: Throwable) : super(cause)
}
我怎样才能实现这一目标?
答案 0 :(得分:7)
这对我有用:
class MyException : RuntimeException {
val status: Status
constructor(status: Status) : super() {
this.status = status
}
constructor(status: Status, cause: Throwable) : super(cause) {
this.status = status
}
}