Getting ready for Kotlin Context Receivers
summary
Experimental Kotlin context receivers require enabling -Xcontext-receivers and compile to functions that the JVM sees as extra parameters — bytecode adds context as parameters — so calls are rewritten at compile time. They work on functions, classes, interfaces and SAMs, handle generics, and ambiguous methods resolve via explicit at-qualifiers. Nested with/apply blocks remain a pain but custom helpers (author shows a with-multiple-receivers helper using generics and a suppression) solve it. Not production-recommended yet and no multiplatform support, but full language support is likely next year.
AI-written summary · about
chapters (19)
- 0:00Introduction and speaker intro
- 1:03What are context receivers
- 3:53Basic usage and width statements
- 5:15Context receivers on classes and interfaces
- 7:48SAM types and context resolution
- 8:29Handling duplicate method names
- 9:56Context receivers with generics
- 11:02How context receivers work under the hood
- 13:09Avoiding nested with statements
- 14:14When to use context receivers
- 16:20Android examples with context receivers
- 19:55Business logic in view models
- 20:58Context receivers in Compose
- 24:35Compose slot APIs and extension functions
- 26:43Alternatives to with statements
- 28:08Custom width for multiple contexts
- 30:19Future of context receivers
- 32:26Dependency injection potential
- 33:08Cautions and multiplatform support








