In the previous chapter, we discussed concepts related to functional programming and functions as first-class citizens in Kotlin.
In this chapter, we will discuss the concepts of generic types and generic functions, known as generics. We will learn why they exist and how to use them and also how to define generic classes, interfaces, and functions. We will discuss how to deal with generics at runtime, take a look at subtyping relations, and deal with generic nullability.
In this chapter, we will cover the following topics:
- Generic classes
- Generic interfaces
- Generic functions
- Generic constraints
- Generic nullability
- Variance
- Use-site target versus declaration-site target
- Declaration-site target
- Type erasure
- Reified and erased type parameters
- Star-projection syntax
- Variance