vault backup: 2022-09-30 21:13:03

Affected files:
.obsidian/workspace
03. Programming/Kotlin/class.md
03. Programming/Kotlin/run, let, with, also 和 apply.md
This commit is contained in:
2022-09-30 21:13:03 +08:00
parent 1bdc3bcd8c
commit 5ee739faf9
3 changed files with 28 additions and 6 deletions

10
.obsidian/workspace vendored
View File

@@ -9,7 +9,7 @@
"state": {
"type": "markdown",
"state": {
"file": "03. Programming/Kotlin/class.md",
"file": "03. Programming/Kotlin/run, let, with, also 和 apply.md",
"mode": "source",
"source": true
}
@@ -69,7 +69,7 @@
"state": {
"type": "backlink",
"state": {
"file": "03. Programming/Kotlin/class.md",
"file": "03. Programming/Kotlin/run, let, with, also 和 apply.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
@@ -86,7 +86,7 @@
"state": {
"type": "outline",
"state": {
"file": "03. Programming/Kotlin/class.md"
"file": "03. Programming/Kotlin/run, let, with, also 和 apply.md"
}
}
}
@@ -116,6 +116,7 @@
},
"active": "828beb43bb437dd1",
"lastOpenFiles": [
"03. Programming/Kotlin/class.md",
"01. 個人/02. 專注Study/RxKotlin/20200207 - Study RxKotlin.md",
"01. 個人/01. Daily/2021/08/2021-08-16(週一).md",
"01. 個人/01. Daily/2021/08/2021-08-14(週六).md",
@@ -124,7 +125,6 @@
"01. 個人/01. Daily/2020/12/2020-12-11(Fri).md",
"01. 個人/01. Daily/2020/12/2020-12-09(Wed).md",
"01. 個人/01. Daily/2018/2018-10-12(週五).md",
"00. Inbox/00. Inbox/A cheatsheet of modern C++ language and library features.md",
"00. Inbox/00. Inbox/Modern C++ use in Chromium.md"
"00. Inbox/00. Inbox/A cheatsheet of modern C++ language and library features.md"
]
}

View File

@@ -39,7 +39,7 @@ class VerySimple(val para1: Int, val para2: String ) {
}
```
## init區塊
## `init` 區塊
`init`是個優先權高於「主要constructor」的執行區塊如下
```kotlin
class VerySimple(val para1: Int, val para2: String ) {

View File

@@ -0,0 +1,22 @@
run, let, with, also 和 apply 這幾個都是可以搭配object 使用的函數,它們之間的差異不大,主要是讓程式看起來更符合語意。
以下解釋各個的差別。
## run
run後面的區塊會回傳「最後一行」所以可以進行「串接」。如下
```kotlin
run {
val telephone = Telephone()
telephone.whoCallMe = "English"
telephone // <-- telephone 被帶到下一個 Chain
}.callMe("Softest part of heart") // <-- 這裡可以執行 `Telephone` Class 的方法
```
## object.run
object.run跟[[run, let, with, also 和 apply#run]]是一樣的只是object.run是讓object呼叫的而且lambda scope中的物件會變成this如下
```kotlin
val anObject = MyObject()
anObject.run {
this.doSomething() // this就是anObject
}
```