- Functional Kotlin
- Mario Arias Rivu Chakraborty
- 147字
- 2021-06-24 19:15:22
Generics
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 Oven: Machine<Bakeable>
Now, Oven is extending Machine with the Bakeable type parameter, so the process method now takes Bakeable as a parameter.
- C# 7 and .NET Core Cookbook
- Learning Cython Programming(Second Edition)
- CMDB分步構建指南
- PHP 從入門到項目實踐(超值版)
- 零基礎玩轉區塊鏈
- Mastering phpMyAdmin 3.4 for Effective MySQL Management
- Python深度學習
- Responsive Web Design with HTML5 and CSS3
- Raspberry Pi for Secret Agents(Third Edition)
- 軟件測試工程師面試秘籍
- Python程序設計
- 微信小程序入門指南
- Elasticsearch Essentials
- Java Web應用開發項目教程
- ABAQUS6.14中文版有限元分析與實例詳解