- 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 Adobe Captivate 2017(Fourth Edition)
- 數據庫系統原理及MySQL應用教程
- Oracle數據庫從入門到運維實戰
- 小型編譯器設計實踐
- Extending Unity with Editor Scripting
- 現代C:概念剖析和編程實踐
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- 深入淺出Python數據分析
- Web前端開發最佳實踐
- C Primer Plus(第6版)中文版【最新修訂版】
- Moodle 3.x Developer's Guide
- Computer Vision with Python 3
- C語言從入門到精通(第4版)
- Go Programming Cookbook(Second Edition)
- C#入門經典(第7版):C# 6.0 & Visual Studio 2015(.NET開發經典名著)