当前位置:网站首页>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 .
边栏推荐
- Pyqt5 rapid development and actual combat 5.4 web page interaction
- Standard C language learning summary 10
- Rhcsa first day
- What is the difference between inline elements and block level elements? Semantic function
- Two global variables__ Dirname and__ Further introduction to common functions of filename and FS modules
- 标准C语言学习总结10
- RHCSA第一天
- [NLP] generate word cloud
- Nano gold coupled antibody / protein Kit (20nm, 1mg/100 μ g/500 μ G coupling amount) preparation
- 迪赛智慧数——折线图(堆叠面积图):2022年不同职业人群存款额占月收入比例排名
猜你喜欢

Explain the remote debugging program of visual studio 2015 in LAN

Future trend of defi in bear market

记录Flutter解决A RenderFlex overflowed by 7.3 pixels on the bottom溢出问题

株洲市九方中学开展防溺水、消防安全教育培训活动

I have been in the industry for 4 years and changed jobs twice. I have understood the field of software testing~

Make trouble fishing day by day

Mesh data generation function meshgrid

In Kingbase, the user is specified to search the schema by default, or the user cannot use the function under the public schema

Technology selection rust post analysis

How to establish a decentralized community in Web3
随机推荐
[hero planet July training leetcode problem solving daily] dynamic planning on the 28th
株洲市九方中学开展防溺水、消防安全教育培训活动
PCB材料简单介绍
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
What testing services do third-party software testing institutions provide? Charging standard of software test report
Why is 0.1 + 0.2 not equal to 0.3? How to solve this problem?
使用Mock技术帮助提升测试效率的小tips,你知道几个?
使用百度EasyDL实现明厨亮灶厨师帽识别
HCIA comprehensive experiment (take Huawei ENSP as an example)
Oracle built-in functions
Oracle triggers
Knowledge description framework of foreign patent documents based on knowledge elements
msfvenom制作主控与被控端
No swagger, what do I use?
Rhcsa first day
39. 组合总和
Which brand is the best and most cost-effective open headset
Clearing of applet component timer
小程序 canvas 生成海报
How to search images efficiently and accurately? Look at the lightweight visual pre training model