当前位置:网站首页>Learn kotlin - extension function
Learn kotlin - extension function
2022-07-28 22:09:00 【Xiao Chen knocked the code randomly】
Extend the functionality
What is extended functionality ?
seeing the name of a thing one thinks of its function , Extension functions are functions that help us extend the functions of classes without touching their code .
let me put it another way ,Kotlin The extension function in allows us to extend the function of the class by adding new functions . This class doesn't have to belong to us ( It can be a third-party library ), We don't need to inherit this class .
Take a very simple example to understand .
fun Int.triple(): Int {
return this * 3
}
// now we can use like this
var result = 3.triple()
Another example , Let's see how Android View Use it in .
fun ImageView.loadImage(url: String) {
Glide.with(context).load(url).into(this)
}
// now we can use like this
imageView.loadImage(url)
It looks great !
stay Android There are many places in the development , We can use Kotlin This cool feature . Let's use this powerful function when we need it .
边栏推荐
- Implementation of sequence table
- How to design workflow engine gracefully (glory Collection Edition)
- 第 7 篇:绘制旋转立方体
- Make trouble fishing day by day
- C语言编程规范学习笔记和总结
- get和post的区别
- How is nanoid faster and more secure than UUID implemented? (glory Collection Edition)
- [machine learning] naive Bayesian classification of text -- Classification of people's names and countries
- 第 8 篇:创建摄像机类
- 详解visual studio 2015在局域网中远程调试程序
猜你喜欢

39. 组合总和

No swagger, what do I use?

What technology is needed for applet development

如何在 Web3中建立一个去中心化社区

系统分析师

Using Baidu easydl to realize chef hat recognition of bright kitchen and stove

Soft test --- database (3) data operation

罗克韦尔AB PLC RSLogix数字量IO模块基本介绍

使用Mock技术帮助提升测试效率的小tips,你知道几个?

如何高效、精准地进行图片搜索?看看轻量化视觉预训练模型
随机推荐
Two global variables__ Dirname and__ Further introduction to common functions of filename and FS modules
拥抱开源指南
Esp8266 Arduino programming example - deep sleep and wake up
Kubevera plug-in addons download address
LVS+KeepAlived高可用部署实战应用
小程序 canvas 生成海报
The applet listens for the target node to appear on the screen
How to establish a decentralized community in Web3
AimBetter洞察您的数据库,DPM 和 APM 解决方案
Make trouble fishing day by day
How to search images efficiently and accurately? Look at the lightweight visual pre training model
Open earphone which air conduction earphone with good sound quality and recognized sound quality is recommended
微信小程序开发公司你懂得选择吗?
科大讯飞笔试
Principle of object. Prototype. ToString. Call()
熊市下 DeFi 的未来趋势
Nano gold coupled antibody / protein Kit (20nm, 1mg/100 μ g/500 μ G coupling amount) preparation
Knowledge description framework of foreign patent documents based on knowledge elements
【云原生之kubernetes】在kubernetes集群下的映射外部服务—Eendpoint
使用Mock技术帮助提升测试效率的小tips,你知道几个?