jeggy
08/26/2022, 1:43 PMcopy function on a generic type? I would like to change the generic type of T to make sure that it's a data class . Or is this just impossible?
fun <T: Any> doCopy(dataObject: T): T {
return dataObject.copy()
}August Lilleaas
08/26/2022, 1:44 PMAugust Lilleaas
08/26/2022, 1:45 PMjeggy
08/26/2022, 1:48 PMinline fun <reified T: Any> doCopy(dataObject: T): T {
return dataObject.copy()
}hfhbd
08/26/2022, 1:48 PMCopyable interface or similar.jeggy
08/26/2022, 1:50 PMhfhbd
08/26/2022, 1:50 PMinterface Copyable<T> {
fun doCopy(): T
}
data class Foo(val s: String): Copyable<Foo> {
override fun doCopy() = copy()
}Ruckus
08/26/2022, 1:53 PMhfhbd
08/26/2022, 3:25 PM