Jiri Bruchanov
07/19/2022, 3:35 PMJiri Bruchanov
07/19/2022, 3:35 PMimport kotlin.reflect.KClass
interface NavArgs
interface LifecycleComponent
interface NavToken<T : NavArgs>
class NavRecord<T : NavArgs, LC : LifecycleComponent>(
val navToken: NavToken<T>,
val klass: KClass<out LC>,
val content: (LC) -> Unit
) {
fun execute(lc: LC) {
content(lc)
}
}
inline fun <reified LC : LifecycleComponent, T : NavArgs> screen(
navToken: NavToken<T>,
noinline content: (LC) -> Unit
): NavRecord<T, LC> = NavRecord(navToken, LC::class, content)
class MyLifecycleComponent/* : LifecycleComponent */
object Stats : NavToken<NavArgs>
fun main() {
val record = screen(Stats) { component: MyLifecycleComponent ->
//why is this working ^^
}
//this is correctly failing because of types
NavRecord(Stats, MyLifecycleComponent::class, { lc: MyLifecycleComponent -> })
record.execute(MyLifecycleComponent())
}
Jiri Bruchanov
07/19/2022, 3:36 PMscreen(...)
isn't compiler errorLandry Norris
07/19/2022, 3:43 PMJiri Bruchanov
07/19/2022, 3:44 PMclass MyLifecycleComponent : LifecycleComponent
having ^ type as expected just compiles fineJiri Bruchanov
07/19/2022, 3:45 PMval record = screen(Stats) { component: MyLifecycleComponent ->
//why is this working ^^
}
just doesn't care if MyLifecycleComponent
is NOT LifecycleComponent
Landry Norris
07/19/2022, 3:46 PMLandry Norris
07/19/2022, 3:46 PMJiri Bruchanov
07/19/2022, 3:48 PMval record = screen(Stats) { component: MyLifecycleComponent -> }
^ to be a compiler issue as MyLifecycleComponent
is NOT LifecycleComponent
Jiri Bruchanov
07/19/2022, 3:49 PM