pixel
pixel

Reputation: 26441

Call super in constructor and assign a field in Kotlin?

I would like to initialise status field inside constructor apart of calling super.

class MyException : RuntimeException {

    init {
        val status: Status
    }

    constructor(status: Status) : super()

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

}

How can I achievie that?

Upvotes: 2

Views: 5658

Answers (1)

voddan
voddan

Reputation: 33749

That worked for me:

class MyException : RuntimeException {
    val status: Status

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

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

Upvotes: 9

Related Questions