Android Engineers reposted this
Most devs use aComposable daily… but don’t know what it actually does. Here’s the clearest, save-worthy breakdown of aComposable you’ll read today. 💚 1) What aComposable really is It’s just an annotation… with superpowers. public annotation class Composable Add it to a function/type → the Compose compiler treats that code differently (state, position, recomposition). 2) Why retention = BINARY (not RUNTIME) - The Compose compiler reads it from .class files. - No runtime reflection = zero runtime tax. - Tools/IDE still see it. ✅ Performance win + great tooling. 3) Where you can put it (targets) - FUNCTION → aComposable fun Screen() - TYPE → val block: aComposable () -> Unit - TYPE_PARAMETER → fun Wrapper(content: aComposable () -> Unit) - PROPERTY_GETTER → val title: String aComposable get() = stringResource(R.string.app_name) 4) The invisible parameter mental model What you write: aComposable fun Greeting(name: String) { Text("Hello, $name") } What the compiler conceptually generates: fun Greeting(name: String, $composer: Composer) { Text("Hello, $name", $composer) } $composer tracks position in the UI tree, remembers values, and enables smart recomposition. 5) The rule that bites beginners ❌ Can’t call a composable from a regular function: fun notComposable() { Text("Hi") // ERROR } ✅ Do this instead: aComposable fun MyScreen() { Text("Hi") } 6) Why the design works - Type Safety → compiler stops illegal calls - Performance → BINARY retention avoids runtime costs - Flexibility → multiple targets cover real-world Compose patterns - Recomposition → only affected nodes re-execute 7) Pocket diagram to remember Data → aComposable functions → UI tree → Screen ↑ ↓ └────── Recomposition ──┘ 8) Copy-paste cheat sheet (save this 🔖) // FUNCTION aComposable fun MyButton() { /* UI */ } // TYPE val content: aComposable () -> Unit = { Text("Hi") } // TYPE_PARAMETER fun Container(body: aComposable () -> Unit) { body() } // PROPERTY_GETTER val title: String aComposable get() = stringResource(R.string.app_name) What’s one thing about aComposable that confused you when starting with Compose? Drop your story or a gotcha below — I’ll reply to every comment. 👇 If this clarified something, comment 💚 so I know to make the next deep dive. #JetpackCompose #androidDev #Kotlin Android Developers #ComposeCompiler #AndroidEngineers