when I learning the Android development techniques,I often access the Google Android Development website ,And I fond there are lots of kotlin example codes use the very tidy writing; but I was not understood well,so I study the related knowledge about kotlin lambda programming techniques and the simplied writting and the regularities(the functional api programming)
example code:
Thread {
println("Thread is running")
}.start()
original version:
from java:
newThread(newRunnable() {
@Override
publicvoidrun() {
System.out.println("Thread is running");
}
}).start();
to kotlin:
Thread(object : Runnable {
overridefunrun() {
println("Thread is running")
}
}).start()
simplified 1:
Thread(Runnable {
println("Thread is running")
}).start()
the Runnable (it’s a signal abstract method Interface) instance is the only one(There is one and only one Java single abstract method interface parameter) (without other singal abstract method Interface instance as parameter) of the Thread constructor to instantiate a instance, as the kotlin syntax,we can omit the Interface name:Runnable;
simplified 2:
Thread({
println("Thread is running")
}).start()
what’s more , the Thread() method has no other parameter,then the parenthesis could be omit too:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2023-04-01 ML@python@稀疏矩阵的存储和表示@CSR格式
2023-04-01 从键盘输入若干 整数(零表示结束), 统计出 数据个数, 以及最大值、最小值和平均值。
2022-04-01 linux_系统编程系统库调用和函数所在头文件的查询/apropos获取按功能查找命令/查找头文件所在目录