February 2018
Intermediate to advanced
350 pages
7h 35m
English
This section is just a short introduction to generics; later, we'll cover it in detail.
Generic programming is a style programming that focuses on creating algorithms (and collaterally, data structures) that work on general problems.
The Kotlin way to support generic programming is using type parameters. In a few words, we wrote our code with type parameters and, later on, we pass those types as parameters when we use them.
Let's take, for example, our Oven interface:
interface Oven { fun process(product: Bakeable)}
An oven is a machine, so we could generalize it more:
interface Machine<T> { fun process(product: T)}
The Machine<T> interface defines a type parameter T and a method process(T).
Now, we can extend it with Oven:
interface ...
Read now
Unlock full access