In other languages like Swift, there is the possibility of creating a function extension that adds a new constructor.
Something like this:
// base c
You can't do this. What you can do though: Extend the companion
object of a class with a factory method:
// base class
class Whatever() {
companion object {
}
}
// factory extension
fun Whatever.Companion.withPotato(potato: String) {
//setPotato(potato)
}
fun main(args: Array) {
println(Whatever.withPotato("holi"))
}
The only problem: A companion
object has to be existent to do this.