当前位置:网站首页>Function extension, attribute extension and non empty type extension in kotlin
Function extension, attribute extension and non empty type extension in kotlin
2022-07-07 08:14:00 【yu-Knight】
val myStr: String = "AAA"
// Extended attributes
val String.myInfo: String
get() = "yuknight"
fun String.showPrintln(): String {
println(" Printout , Parallel chain call , The content is :$this")
return this
}
val String.strValue: String
get() = " At present ${System.currentTimeMillis()}, Call once , The value is :$this, The length is $length"
// Yes String?== Function extension of null type
fun String?.outputStrValueF(defaultValue:String) = println(this ?: defaultValue)
fun String?.outputStrValueFget(defaultValue: String) = if (this == null) defaultValue else this
fun main(){
val str:String = "ABC"
println(str.myInfo)
// spread function
str.showPrintln().showPrintln().showPrintln()
// Extended attributes
str.myInfo.showPrintln().showPrintln()
"yuknight".strValue.showPrintln().showPrintln()
/****************************************/
val infoValue:String? = null //infoValue It's a nullable type String String?== Null type
infoValue.outputStrValueF(" The default value is 1")
val name = "yuknight"
name.outputStrValueFget(" The default value is 2")
println(infoValue.outputStrValueFget(" The default value is 3"))
println(name.outputStrValueFget(" The default value is 4"))
}
边栏推荐
- Complex network modeling (III)
- LeetCode简单题之找到一个数字的 K 美丽值
- Application of slip ring of shipborne radar antenna
- It's too true. There's a reason why I haven't been rich
- Leetcode medium question my schedule I
- Register of assembly language by Wang Shuang
- 使用 Nocalhost 开发 Rainbond 上的微服务应用
- 【数字IC验证快速入门】12、SystemVerilog TestBench(SVTB)入门
- 拓维信息使用 Rainbond 的云原生落地实践
- Real time monitoring of dog walking and rope pulling AI recognition helps smart city
猜你喜欢
eBPF Cilium实战(2) - 底层网络可观测性
发挥创客教育空间的广泛实用性
Leetcode medium question my schedule I
柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
The largest 3 same digits in the string of leetcode simple question
CDC (change data capture technology), a powerful tool for real-time database synchronization
漏洞複現-Fastjson 反序列化
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
海信电视开启开发者模式
漏洞复现-Fastjson 反序列化
随机推荐
【数字IC验证快速入门】10、Verilog RTL设计必会的FIFO
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
Blob object introduction
Use of JMeter
Basic use of CTF web shrink template injection nmap
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Network learning (II) -- Introduction to socket
运放电路的反馈电阻上并联一个电容是什么作用
漏洞复现-easy_tornado
Avatary's livedriver trial experience
青龙面板--整理能用脚本
jeeSite 表单页面的Excel 导入功能
一文了解如何源码编译Rainbond基础组件
让Livelink初始Pose与动捕演员一致
机器人教育在动手实践中的真理
Make LIVELINK's initial pose consistent with that of the mobile capture actor
Empire CMS collection Empire template program general
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
DNS server configuration
Interactive book delivery - signed version of Oracle DBA work notes