- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 126字
- 2021-06-24 19:15:22
Type alias
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
推薦閱讀
- Functional Python Programming
- 極簡(jiǎn)算法史:從數(shù)學(xué)到機(jī)器的故事
- 老“碼”識(shí)途
- Java EE 7 Development with NetBeans 8
- 嚴(yán)密系統(tǒng)設(shè)計(jì):方法、趨勢(shì)與挑戰(zhàn)
- Python機(jī)器學(xué)習(xí)算法: 原理、實(shí)現(xiàn)與案例
- Java面向?qū)ο蟪绦蛟O(shè)計(jì)
- Python:Deeper Insights into Machine Learning
- Laravel Application Development Blueprints
- C語言程序設(shè)計(jì)
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)
- C語言從入門到精通
- Java服務(wù)端研發(fā)知識(shí)圖譜
- 讀故事學(xué)編程:Python王國(guó)歷險(xiǎn)記
- 走近SDN/NFV