伴生对象
This commit is contained in:
parent
3088c891a0
commit
b7cafa32f4
14
src/class/Companion/Rain.kt
Normal file
14
src/class/Companion/Rain.kt
Normal file
@ -0,0 +1,14 @@
|
||||
package `class`.Companion
|
||||
|
||||
class Rain {
|
||||
companion object Timemail {
|
||||
fun say() {
|
||||
println("伴生对象")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Rain.say()
|
||||
Rain.Timemail.say()
|
||||
}
|
||||
13
src/class/Single/Singleton.kt
Normal file
13
src/class/Single/Singleton.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package `class`.Single
|
||||
|
||||
object Singleton {
|
||||
var name = "单例模式"
|
||||
fun say(){
|
||||
println("Hello $name !")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Singleton.name = "World"
|
||||
Singleton.say()
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user