eygraber
09/06/2021, 4:13 AMinterface Renderer {
fun render()
}
interface ComposeRenderer : Renderer {
@Composable override fun render()
}
will the compose mechanics work correctly if I call render
polymorphically?
class MyActivity : AppCompatActivity {
private val renderer: Renderer = object : ComposableRenderer ...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { renderer.render() }
}
}
Albert Chang
09/06/2021, 4:16 AM@Composable
in your interface because @Composable
changes the signature of the function.eygraber
09/06/2021, 4:20 AMComposableRenderer
.
What about a case where the compiler can't deterministically see that it's a ComposableRenderer
?Albert Chang
09/06/2021, 4:23 AMeygraber
09/06/2021, 6:11 AMAlbert Chang
09/06/2021, 6:22 AMeygraber
09/06/2021, 7:00 AMRenderer.render
which is not marked as composable. It has no idea that the actual Renderer implementation is ComposableRenderer
, so I'd imagine that it wouldn't transform the signature.
My question is then essentially, is there any way the compiler can infer that this actually is a composable call, and if not, I just want to confirm that the composable function wouldn't work.Albert Chang
09/06/2021, 7:08 AM@Composable
in your interface.hfhbd
09/06/2021, 8:44 AMinterface ComposeRenderer : @Composable () -> Unit
In theory, this should work too, but I never tried it out.eygraber
09/06/2021, 4:35 PMRenderer
and ComposeRenderer
to stay as declared above.Zach Klippenstein (he/him) [MOD]
09/07/2021, 2:15 PM