- 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.
- Mastering Entity Framework Core 2.0
- JMeter 性能測試實戰(第2版)
- Mastering Python Scripting for System Administrators
- INSTANT MinGW Starter
- C語言程序設計
- Mastering Swift 2
- 零基礎學Python數據分析(升級版)
- Oracle 18c 必須掌握的新特性:管理與實戰
- OpenMP核心技術指南
- IDA Pro權威指南(第2版)
- Web程序設計:ASP.NET(第2版)
- STM8實戰
- Learning Concurrency in Python
- Access數據庫應用教程(2010版)
- Java高級程序設計