Unit 02 of 03
Types and Null Safety
Nullable and non-nullable types, safe calls and the Elvis operator, primary and secondary constructors, data classes, sealed types and enumerations, object declarations, interfaces and delegation, extension functions, and generics and variance.
Published Updated
Lessons
- 01 Null Safety A measurement of how nullable and non-nullable types are separate types, how a type narrows after a null check, and which criterion null equal to null produces. 15 min read
- 02 Safe Calls and the Elvis Operator A measurement of where a safe call chain stops when it meets null, when the Elvis operator evaluates its right side, and which exception a not-null assertion throws. 15 min read
- 03 Classes and Constructors A measurement of the execution order of the primary constructor, the init block, and the secondary constructor, and of why instances of a class without equals fall to the identity criterion. 14 min read
- 04 Data Classes A measurement of the methods a data class generates from the properties in its primary constructor, of the separate object built with copy, and of how the type of a field affects the criterion. 15 min read
- 05 Sealed Types and Enumerations A measurement of which criterion an enum entry, a data object, a data class, and an ordinary class fall to in the same sealed hierarchy, and of how an exhaustive when rejects a missing branch. 14 min read
- 06 Object Declarations Measures the object declaration, the companion object, the `data object`, and the object expression with the criterion that makes two values equal, and shows that a declaration is a singleton while an expression builds a new object on every evaluation. 15 min read
- 07 Interfaces and Delegation Measures the interface, the default implementation, and delegation with `by` using the criterion that makes two values equal, and shows that delegation forwards the members of the interface but does not forward `equals`. 14 min read
- 08 Extension Functions Writes an extension function, an extension property, and an extension on a nullable receiver, and measures that an extension cannot shadow a member and is chosen by the static type. 16 min read
- 09 Generics and Variance Measures a generic class, a generic function, an upper-bound constraint, `out` and `in` variance, and type erasure; shows that the type parameter is erased at run time and that equality looks at the value. 15 min read