Nathan Bedell
10/15/2021, 1:57 PMclass 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:
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.dmitriy.novozhilov
10/15/2021, 2:22 PMinterface 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?
}