y
06/18/2025, 3:30 PMinterface HasFoo {
val foo: Foo
}
I want something like
sealed interface UpdateableFoo : Foo {
fun updateFoo(newFoo: Foo): Self
}
where Self is a self type (not supported in Kotlin, as per my understanding).
what's the least messy way of doing this?
should I just not use an interface, and use an extension function fun <T: HasFoo> updateFoo(newFoo: Foo): T instead?
(edit: actually, I don't think I can do that, since HasFoo isn't sealed and so I can't enumerate the `HasFoo`s inside updateFoo...?)ephemient
06/18/2025, 3:42 PMinterface Iface<T : Iface<T>> {
fun copy(): T
}
class Impl : Iface<Impl>
but they're impossible to work safely with in many waysy
06/18/2025, 3:48 PMcopy() function to the relevant classesYoussef Shoaib [MOD]
06/18/2025, 3:59 PMT. That's the simplest way I'd do it. I don't think it's unreasonable to expect implementers to return an instance of that same class (you could even do reified if you want the cast to be checked)