Kotlin & Coroutines (50 Qs)•Part 3: K2 Compiler, KMP, Advanced Metaprogramming & Optimization (25 - 35)
Kotlin Flow Deep Dive: Cold Flows vs Hot Flows (`StateFlow`, `SharedFlow`).
senior LevelPerformance
In Simple Words:
- Cold Flow (
flow { ... }): On-demand stream. Code inside the builder block does not execute until a terminal operator (collect()) is called. Each collector gets its own independent execution. - Hot Flows: Emit values regardless of whether subscribers are currently listening:
StateFlow: State-holder that retains the latest single value (like LiveData). Emits value immediately to new subscribers. Replay cache size = 1.SharedFlow: Event-emitter for one-off events (navigation, snackbars). Supports configurablereplaybuffer sizes and emits events to multiple parallel collectors.