groostav
10/28/2020, 11:50 PMsealed class Configuration {
data class Customer(val name: String, val age: Int): Configuration()
data class User(val email: String): Configuration()
}
class Whatever {
fun doStuff(config: Configuration): Int {
//...
}
}
and I would like kotlin to do something automagical with
w.doStuff("bob", 42) // --calls Customer.<init>, doStuff()
w.doStuff("<mailto:jane_doe@email.com|jane_doe@email.com>") // calls User.<init>, doStuff()
I feel like I use sealed-classes as a way to expand a functions capability a lot. Right now (at least 3x in recent memory), I'll add exension functions to call the constructor and the method for you. eg
fun Whatever.doStuff(name: String, age: Int) = doStuff(Customer(name, age))
but this is kinda tedious, and i feel like the compiler could do it for me.groostav
10/28/2020, 11:51 PM@JvmImpliedOverloads
for kotlinc?dmitriy.novozhilov
10/29/2020, 1:17 PMsealed class Configuration {
data class Customer(val name: String, val age: Int): Configuration()
data class User(val email: String, val id: Int): Configuration()
}