Hello, I'm having a base class like this: ```abstr...
# compose
l
Hello, I'm having a base class like this:
Copy code
abstract 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:
Copy code
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?
o
Not sure why this happens, but did you try to not pass
content
lambda directly, but instead call it?
Copy code
fun setContent(content: @Composable () -> Unit) {
    composition = Composition(/* ... */).apply { setContent { content() } }
}
l
Same error :(
😞 1
Honestly is this a java interop issue? I added that the
Scene
is a derived class from a java class
and that init comes from that java class
'Cause I test this with pure kotlin, nothing happens.
o
Honestly is this a java interop issue?
Could be 🤷 Never has to work with Java & Compose 😕
l
Maybe derived class from java has different behavior during the compile time, and compose don't get it.
But abstract method
@Composable abstract fun content()
works properly.
🤔 1