I was reading someone's code for some thing and found this strange class definition
Copy code
class Usage(from: List<UsageArgument> = listOf(), val runsAt: List<RunAt> = listOf()) : List<UsageArgument> by from {
override fun toString(): String {
val result = joinToString(" ") { it.format() }
return if (result.isBlank()) "none" else result
}
}
can anyone explain this to me?
especially the parameters of the class def and the ending "by from". what does it mean?
the use case is like a list or something i suppose?
to wrap your head around it , look at delegation pattern before hand.
r
Ray Eldath
01/26/2020, 6:49 PM
off-topic: i remembered KotlinConf 2018 Closing Panel someone pointed delegation as their most hateful feature. and in ktconf 2019 Andrej says delegation is what he want to redesign most, IIRC.