Explain Kotlin's declaration-site variance with `in` and `out`

This tests your grasp of type systems and API design. Explain how `out` (covariance/producer) and `in` (contravariance/consumer) provide type safety at the declaration site, simplifying usage. A red flag is confusing variance with immutability.
This question tests your deep understanding of Kotlin's type system and its impact on API design. A strong answer defines covariance (`out`, producer) and contravariance (`in`, consumer), then explains how annotating the declaration simplifies API usage compared to Java's use-site wildcards. A major red flag is conflating variance with immutability or simply describing the syntax without explaining the 'why'—the producer/consumer pattern.
Read the original → kotlinlang.org
- #kotlin
- #generics
- #api design
- #type system
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.