https://kotlinlang.org logo
Title
h

Hullaballoonatic

06/24/2019, 7:35 PM
In cases when utilizing types such as
interface Foo<F: Foo<F>>
I'm always confused by when I can define a type as
interface Foo<F: Foo<F>> {
    val incorrect: F // why can I almost never define it like this?
    val correct: Foo<F> // why does the type require Foo<F>, when F is already Foo<F>?
}
s

streetsofboston

06/24/2019, 7:47 PM
Not sure. Your code snippet compiles fine
interface Foo<F: Foo<F>> {
    val incorrect: F // why can I almost never define it like this?
    val correct: Foo<F> // why does the type require Foo<F>, when F is already Foo<F>?
}

class FooImpl: Foo<FooImpl> {
    override val incorrect: FooImpl get() = TODO("not implemented")
    override val correct: Foo<FooImpl> get() = TODO("not implemented")
}