October 2021
Intermediate to advanced
500 pages
16h 23m
English
You learned in Chapter 9 that a list can hold any type – integers, strings, or even new types that you have defined:
val listOfInts: List<Int> = listOf(1, 2, 3)
val listOfStrings: List<String> = listOf("string one", "string two")
val listOfRooms: List<Room> = listOf(Room(), TownSquare())
Lists can hold any type because of generics, a type system feature that allows both functions and types to work with types that are not yet known to you or the compiler. Generics greatly expand the reusability of your class definitions, because they allow your definitions to work with many types.
In this chapter, you will create your own generic classes and functions that work with generic type parameters. You will be adding ...
Read now
Unlock full access