English
Topic 9. Generic programming: generic classes and functions, variance, reified parameters
Goal: learn to design generic types, specify sufficient constraints, distinguish producers from consumers, and verify both the behavior and the static contract of your own API.
Lecture contents
- Type parameters and generic classes — A type parameter as part of the contract · Example 1. A stack on linked nodes
- Generic functions and bounds — Generic functions and constraints · Nullable bounds and definitely non-null
- Variance and projections — Invariance: why an element subtype is not enough · Declaration-site variance · Use-site projections
- Type erasure and reified — Type erasure and reified · Sealed results, Nothing, and aliases
- API design and testing — API design: from operations to variance · Verifying contracts without unchecked casts · Generalization and domain identity