Loney Chou
06/24/2022, 10:45 AMabstract class Scene : JavaScene() { // JavaScene is a Java class
private var composition: Composition? = null
fun setContent(content: @Composable () -> Unit) {
composition = Composition(/* ... */).apply { setContent(content) }
}
}
and a subclass like this:
class MyScene : Scene() {
override fun init() { // From JavaScene
setContent { /* ... */ }
}
}
Nothing complains during the compile time, but at the runtime when init
gets called, Scene.setContent
throws an error: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0
. How to fix that?Oleksandr Balan
06/24/2022, 12:05 PMcontent
lambda directly, but instead call it?
fun setContent(content: @Composable () -> Unit) {
composition = Composition(/* ... */).apply { setContent { content() } }
}
Loney Chou
06/24/2022, 12:14 PMScene
is a derived class from a java classOleksandr Balan
06/24/2022, 12:17 PMHonestly is this a java interop issue?Could be 🤷 Never has to work with Java & Compose 😕
Loney Chou
06/24/2022, 12:27 PM@Composable abstract fun content()
works properly.