当前位置:网站首页>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"))
}
边栏推荐
- Zcmu--1492: problem d (C language)
- Codeforce c.strange test and acwing
- Register of assembly language by Wang Shuang
- 藏书馆App基于Rainbond实现云原生DevOps的实践
- 饥荒云服管理脚本
- 运放电路的反馈电阻上并联一个电容是什么作用
- JS cross browser parsing XML application
- 解读创客思维与数学课程的实际运用
- Bugku CTF daily one question chessboard with only black chess
- 【雅思口语】安娜口语学习记录 Part2
猜你喜欢
uniapp 移动端强制更新功能
Record a stroke skin bone error of the skirt
追风赶月莫停留,平芜尽处是春山
漏洞复现-Fastjson 反序列化
UnityHub破解&Unity破解
Network learning (I) -- basic model learning
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Content of string
Application of slip ring of shipborne radar antenna
王爽 《汇编语言》之寄存器
随机推荐
Summary of redis functions
拓维信息使用 Rainbond 的云原生落地实践
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
Avatary的LiveDriver试用体验
追风赶月莫停留,平芜尽处是春山
漏洞复现-easy_tornado
【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
Linux Installation MySQL 8.0 configuration
Blob object introduction
CDC (change data capture technology), a powerful tool for real-time database synchronization
Interactive book delivery - signed version of Oracle DBA work notes
[untitled]
B. Value sequence thinking
JS cross browser parsing XML application
Fast parsing intranet penetration escorts the document encryption industry
Call pytorch API to complete linear regression
Rainbond结合NeuVector实践容器安全管理
Interview questions (CAS)
Blob 對象介紹
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu