I'm curious, has anyone ever proposed anything lik...
# language-proposals
n
I'm curious, has anyone ever proposed anything like this before?
Copy code
class MyGenericClass<interface I: SomeInterface>(): I {...}
Essentially, allowing us to declare a generic type I as an interface -- this allowing classes or other interfaces in the scope of the type parameter I to inherit from I. I've run into a few circumstances where I find myself wanting something like this -- e.x. when I depend on a generic interface, and then I want a class to extend that interface so that within the class I can access that interface's methods/properties directly, rather than by referencing the interface itself, e.x:
Copy code
class MyView<interface I: IMyViewModel>(val vm: I): I by vm { ... }
"View" here (Maybe not the best word) being in a general sense, not an Android View -- something that subscribes to the view model events, and updates the UI accordingly.
d
This is very strange request. What about such example?
Copy code
interface A {
    fun foo()
}

interface B : A {
    fun bar()
}

class MyGenericClass<interface I: A>(): A {
    override fun foo() {}
    
    inner /*???*/ interface Inner : I {
        override fun foo() {}
    }
}

fun test() {
    val x: MyGenericClass<B> = ... // how is MyGenericClass.Inner.bar is implemented?
}