CLOVIS
08/10/2026, 8:38 PMinterface Foo {
fun foo(): Foo
fun bar(): Foo
}
Ideally, it would use self-types, but since we don't have that, instead each implementation must override the return types with itself.
class FooA {
override fun foo(): FooA
override fun bar(): FooA
}
class FooB {
override fun foo(): FooB
override fun bar(): FooB
}
In reality though, Foo has a dozen functions that have a default body. Because of that, I don't get a compilation error if I forget to override them.
Do you have any tricks that would make it easier to detect when an implementation is missing an override?hfhbd
08/10/2026, 8:45 PMpublic interface Foo<out T: Foo<T>> {
public fun foo(): T
public fun bar(): T
public fun baz(): T {
}
}James Richardson
08/10/2026, 8:51 PMJames Richardson
08/10/2026, 8:53 PMCasey Brooks
08/10/2026, 8:53 PMinterface Foo<T: FooT> {
fun foo(): T { return this as T }
fun bar(): T { return this as T }
}
class FooA : FooFooA {
override fun foo(): FooA { TODO() }
override fun bar(): FooA { TODO() }
}
class FooB : FooFooA {
override fun foo(): FooA { TODO() }
override fun bar(): FooA { TODO() }
}CLOVIS
08/10/2026, 8:59 PMinterface FooT {
fun foo(): FooT
fun A map(…): FooA
}
To use self-type emulation here, I'd need higher-kinded types, which we don't haveJames Richardson
08/10/2026, 9:03 PMJames Richardson
08/10/2026, 9:03 PMCLOVIS
08/10/2026, 9:07 PMYoussef Shoaib [MOD]
08/10/2026, 9:09 PMthis, you can make the interface methods return Unit, and provide extensions that are generic on the receiver typeCLOVIS
08/10/2026, 9:49 PMCLOVIS
08/10/2026, 9:50 PMMarat Akhin
08/11/2026, 8:27 AMinterface DefaultFoo {
fun foo(): DefaultFoo = this
}
interface MustOverrideFoo : DefaultFoo {
abstract override fun foo(): MustOverrideFoo
}
class Bad : MustOverrideFoo {
override fun foo(): Bad = this
}
interface DefaultFoo {
fun foo(): DefaultFoo = this
}
interface RequiresFoo {
fun foo(): DefaultFoo
}
class Good : DefaultFoo, RequiresFoo {
override fun foo(): Good = this
}