How to extend a class that has multiple constructors in Kotlin?
Solution 1:
Update: Since M11 (0.11.*), you can use secondary constructors to solve this problem:
class PhotoLibException : RuntimeException {
constructor(message: String, ex: Exception?): super(message, ex) {}
constructor(message: String): super(message) {}
constructor(ex: Exception): super(ex) {}
}
Currently, there's no way to call different super-constructors in different context from the same class. It will be supported in the upcoming months, though.
Solution 2:
Use the @JvmOverloads annotation.
class PhotoLibException: RuntimeException {
@JvmOverloads constructor(message: String, ex: Exception?)
}