Hi everyone. Am I allowed to declare a `@Composable` method on an interface? something like: ```inte...
c
Hi everyone. Am I allowed to declare a
@Composable
method on an interface? something like:
Copy code
interface ImageLoader {
  @Composable
  fun Image(url: String)
}
I have similar code implemented right now, which compiles but throws NoSuchMethodError at runtime
👌 1
z
It’s not crazy, it’s definitely allowed, and the Compose code itself does this!
1
c
ok interesting, the exception I’m getting is
Copy code
java.lang.NoSuchMethodError: No interface method Image(Ljava/lang/String;Ljava/lang/String;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/layout/ContentScale;Landroidx/compose/runtime/Composer;I)V
a
is the compose compiler plugin enabled when compiling both the interface and the implementation class?
c
oooh what a good question… please hold
a
the telltale sign is in that signature: compose adds the
Composer
and the
Int
(the
I
) at the end of a
@Composable
function's parameter list
c
thanks for the tip! Yes, I’d forgotten to enable compose compiler
👍 2
👍🏼 1