Type alias provides a way to define names of types that already exist. Type alias can help to make complex types easier to read, and can also provide other hints.
The Oven
interface is, in some sense, just a name, for a Machine<Bakeable>
:
typealias Oven = Machine<Bakeable>
Our new type alias, Oven
, is exactly like our good old Oven
interface. It can be extended and have the values of the type Oven
.
Types alias also can be used to enhance information on types, providing meaningful names related to your domain:
typealias Flavour = String abstract class BakeryGood(val flavour: Flavour) {
It can also be used on collections:
typealias OvenTray = List<Bakeable>
It can also be used with objects:
typealias CupcakeFactory = Cupcake.Companion