Kotlin variance modifiers and Covariant Object Nothing pattern
summary
Explains the concrete claim that making generics covariant and using Nothing as a placeholder produces single reusable instances (the Covariant Nothing Object pattern) and its sibling for sealed generics (Covariant Nothing Class). Shows the standard library listOf<Nothing> emptyList implementation, demonstrates Arrow-style Either using Nothing, measures the payoff (avoids thousands of allocations per second), and walks limitations: in/out positions, unsafe variance escapes, and why arrays remain invariant compared with Java.
AI-written summary · about
chapters (7)
- 0:00Variance modifiers intro
- 2:08Generic type modifiers
- 6:07Variance use cases
- 14:15Covariant Nothing Object
- 23:16Variance limitations
- 31:32Further resources
- 31:57Q&A








