From 20f946382e74acf7a919e2e10f8ca5fa1e6f1674 Mon Sep 17 00:00:00 2001 From: SOR <3272194354@qq.com> Date: Thu, 17 Sep 2026 21:45:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E5=86=99=E4=B8=80=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Learning/成为Kotlin超人.md | 14 +++++++ Learning/深入Kotlin.md | 83 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 Learning/成为Kotlin超人.md diff --git a/Learning/成为Kotlin超人.md b/Learning/成为Kotlin超人.md new file mode 100644 index 0000000..2ef6ce9 --- /dev/null +++ b/Learning/成为Kotlin超人.md @@ -0,0 +1,14 @@ +# 成为 Kotlin 超人 + +> 来到这里,我不再会给出详尽的用法。
+> 以你的实力,只要我指出在什么时候应该使用什么就够了 + +## 时间 + +## JSON 序列化 + +## Kotlin 协程 + +## 不依赖 Springboot 的网络 api + +## 加载动态链接库(JNA) \ No newline at end of file diff --git a/Learning/深入Kotlin.md b/Learning/深入Kotlin.md index 3853b21..20ba6af 100644 --- a/Learning/深入Kotlin.md +++ b/Learning/深入Kotlin.md @@ -1,5 +1,86 @@ # 深入 Kotlin +确保你已经了解所有的基础语法,这很重要。 + +## 更全面的 class 用法 + +### 更加详细的 class 构造函数与对象初始化 + +#### 类初始化 + +在 Kotlin 的类定义中可以写 `init {}` 代码块,它发生在构造函数之后,作用是使用构造函数定义的成员变量值再做一些构造函数没有的操作,比如利用构造函数的参数再做一些细致的变量处理。 + +#### 构造函数 + +构造函数有多种写法: + +1. 直接写在类名之后 + +```kotlin +class MyClass( + val a: Int, + private var b: String, + c: Int // 这里的变量 c 仅用于成员初始化,随后被抛弃,不作为成员变量 +) { + val d = c * a + // something else +} +``` + +```kotlin +class MyClass private constructor( // 非私有时,constructor 可省 + // ... +) { + // something else +} +``` + +2. 写在类定义之内 + +```kotlin +class MyClass { + val d: Int + constructor( + val a: Int, + private var b: String, + c: Int + ) { + d = c * a + } + // something else +} +``` + +3. 构造函数调用其他构造函数 + +```kotlin +class MyClass( + var name: String?, + val amount: Int +) { + constructor( + val amount: Int + ) : this(null, amount) + // something else +} +``` + + + +## 文件 IO + + + +## 用 Gradle 加载依赖(外部库) + + +## Kotlin 反射 + + + + +```kotlin +``` ## 接下来可以看 @@ -7,4 +88,6 @@ [下一篇:Kotlin Springboot](./Kotlin-Springboot.md) +[更进一步:成为 Kotlin 超人](./成为Kotlin超人.md) + [进入 KMP](./进入KMP.md) \ No newline at end of file