Kotlin secondary constructor of extended class conditional branch super value

Viewed 1091

How do you have conditional super calls based on the value in the fourth secondary constructor? Why doesn't this work?

open class SecondaryConstructors{
    constructor(i:Int)
    constructor(s:String)
}
class SecondaryExtended:SecondaryConstructors {
    constructor(i:Int):super(i)
    constructor(s:String):super(s)
    constructor():super(if(true)1 else 0)
    constructor(intOrString:Boolean):super( if(intOrString) 3 else "hey")
    // conditional branch result of int/string is implicitly cast to Any
    // error - none of the following functions can be called with the arguments supplied
}
1 Answers
Related