Classes and Their Generated Types
Explore Kotlin’s type system, including class-generated types, subtyping relationships, and the roles of Any? and Any.
We'll cover the following...
We'll cover the following...
The relation between classes and types
We say that classes generate types. Think of the User class. It generates two types. Can we name them both?
- One is - User, but the second is not- Any(- Anyis already in the type hierarchy).
- The second new type generated by the class - Useris- User?. Yes, the nullable variant is a separate type.
There are classes that generate many more types: generic classes. The Box<T> class theoretically generates an infinite number of types. ...