官方来源与维护原则¶
本文档库以 Kotlin 官方文档为主线组织内容,并补充中文语境下更容易理解的解释、Java 对比和实践建议。
已对照的官方页面¶
- Kotlin Docs 首页:https://kotlinlang.org/docs/home.html
- Kotlin Tour:https://kotlinlang.org/docs/kotlin-tour-welcome.html
- Basic syntax overview:https://kotlinlang.org/docs/basic-syntax.html
- Packages and imports:https://kotlinlang.org/docs/packages.html
- Visibility modifiers:https://kotlinlang.org/docs/visibility-modifiers.html
- Types overview:https://kotlinlang.org/docs/types-overview.html
- Numbers:https://kotlinlang.org/docs/numbers.html
- Booleans:https://kotlinlang.org/docs/booleans.html
- Characters:https://kotlinlang.org/docs/characters.html
- Strings:https://kotlinlang.org/docs/strings.html
- Arrays:https://kotlinlang.org/docs/arrays.html
- Unsigned integer types:https://kotlinlang.org/docs/unsigned-integer-types.html
- Null safety:https://kotlinlang.org/docs/null-safety.html
- Type checks and casts:https://kotlinlang.org/docs/typecasts.html
- Equality:https://kotlinlang.org/docs/equality.html
- Sequences:https://kotlinlang.org/docs/sequences.html
- Type aliases:https://kotlinlang.org/docs/type-aliases.html
- Inline value classes:https://kotlinlang.org/docs/inline-classes.html
- Ranges and progressions:https://kotlinlang.org/docs/ranges.html
- Returns and jumps:https://kotlinlang.org/docs/returns.html
- Destructuring declarations:https://kotlinlang.org/docs/destructuring-declarations.html
- This expressions:https://kotlinlang.org/docs/this-expressions.html
- Conditions and loops:https://kotlinlang.org/docs/control-flow.html
- Functions:https://kotlinlang.org/docs/functions.html
- Inline functions:https://kotlinlang.org/docs/inline-functions.html
- Functional interfaces:https://kotlinlang.org/docs/fun-interfaces.html
- Nested and inner classes:https://kotlinlang.org/docs/nested-classes.html
- Classes:https://kotlinlang.org/docs/classes.html
- Properties:https://kotlinlang.org/docs/properties.html
- Inheritance:https://kotlinlang.org/docs/inheritance.html
- Interfaces:https://kotlinlang.org/docs/interfaces.html
- Data classes:https://kotlinlang.org/docs/data-classes.html
- Sealed classes and interfaces:https://kotlinlang.org/docs/sealed-classes.html
- Enum classes:https://kotlinlang.org/docs/enum-classes.html
- Generics:https://kotlinlang.org/docs/generics.html
- Extensions:https://kotlinlang.org/docs/extensions.html
- Higher-order functions and lambdas:https://kotlinlang.org/docs/lambdas.html
- Scope functions:https://kotlinlang.org/docs/scope-functions.html
- Context parameters:https://kotlinlang.org/docs/context-parameters.html
- Type-safe builders:https://kotlinlang.org/docs/type-safe-builders.html
- Using builders with builder type inference:https://kotlinlang.org/docs/using-builders-with-builder-inference.html
- Object declarations and expressions:https://kotlinlang.org/docs/object-declarations.html
- Delegation:https://kotlinlang.org/docs/delegation.html
- Delegated properties:https://kotlinlang.org/docs/delegated-properties.html
- Operator overloading:https://kotlinlang.org/docs/operator-overloading.html
- Exception and error handling:https://kotlinlang.org/docs/exceptions.html
- Annotations:https://kotlinlang.org/docs/annotations.html
- Reflection:https://kotlinlang.org/docs/reflection.html
- Coroutines:https://kotlinlang.org/docs/coroutines-overview.html
- Coroutines basics:https://kotlinlang.org/docs/coroutines-basics.html
- Composing suspending functions:https://kotlinlang.org/docs/composing-suspending-functions.html
- Flows:https://kotlinlang.org/docs/coroutines-flow.html
- Coding conventions:https://kotlinlang.org/docs/coding-conventions.html
- Collections overview:https://kotlinlang.org/docs/collections-overview.html
- Collection operations overview:https://kotlinlang.org/docs/collection-operations.html
- Filtering collections:https://kotlinlang.org/docs/collection-filtering.html
- Collection transformation operations:https://kotlinlang.org/docs/collection-transformations.html
- Grouping:https://kotlinlang.org/docs/collection-grouping.html
- Retrieve collection parts:https://kotlinlang.org/docs/collection-parts.html
- Retrieve single elements:https://kotlinlang.org/docs/collection-elements.html
- Ordering:https://kotlinlang.org/docs/collection-ordering.html
- Aggregate operations:https://kotlinlang.org/docs/collection-aggregate.html
- Plus and minus operators:https://kotlinlang.org/docs/collection-plus-minus.html
- Collection write operations:https://kotlinlang.org/docs/collection-write.html
- List-specific operations:https://kotlinlang.org/docs/list-operations.html
- Set-specific operations:https://kotlinlang.org/docs/set-operations.html
- Map-specific operations:https://kotlinlang.org/docs/map-operations.html
- Nullability in Java and Kotlin:https://kotlinlang.org/docs/java-to-kotlin-nullability-guide.html
- Calling Java from Kotlin:https://kotlinlang.org/docs/java-interop.html
- Calling Kotlin from Java:https://kotlinlang.org/docs/java-to-kotlin-interop.html
- Collections in Java and Kotlin:https://kotlinlang.org/docs/java-to-kotlin-collections-guide.html
- Strings in Java and Kotlin:https://kotlinlang.org/docs/java-to-kotlin-idioms-strings.html
- Using Java records in Kotlin:https://kotlinlang.org/docs/jvm-records.html
- Kotlin Multiplatform:https://kotlinlang.org/docs/multiplatform.html
- Kotlin Multiplatform get started:https://kotlinlang.org/docs/multiplatform/get-started.html
- Kotlin/JavaScript:https://kotlinlang.org/docs/js-overview.html
- Kotlin/Native:https://kotlinlang.org/docs/native-overview.html
- Kotlin/Wasm:https://kotlinlang.org/docs/wasm-overview.html
- Get started with Kotlin/Wasm and Compose Multiplatform:https://kotlinlang.org/docs/wasm-get-started.html
- Compose Multiplatform:https://kotlinlang.org/docs/multiplatform/compose-multiplatform.html
- Configure a Gradle project:https://kotlinlang.org/docs/gradle-configure-project.html
- Compiler options in the Kotlin Gradle plugin:https://kotlinlang.org/docs/gradle-compiler-options.html
- Kotlin compiler options:https://kotlinlang.org/docs/compiler-reference.html
- Kotlin evolution principles:https://kotlinlang.org/docs/kotlin-evolution-principles.html
- Kotlin language features and proposals:https://kotlinlang.org/docs/kotlin-language-features-and-proposals.html
- What's new in Kotlin 2.2.0:https://kotlinlang.org/docs/whatsnew22.html
- Test Java code using Kotlin and JUnit:https://kotlinlang.org/docs/jvm-test-using-junit.html
- Serialization:https://kotlinlang.org/docs/serialization.html
- Kotlin Standard Library API:https://kotlinlang.org/api/core/
- Backend development with Kotlin:https://kotlinlang.org/docs/server-overview.html
- Ktor create, open, and run a new project:https://ktor.io/docs/server-create-a-new-project.html
- Create a Spring Boot project with Kotlin:https://kotlinlang.org/docs/jvm-create-project-with-spring-boot.html
- Spring Boot Kotlin Support:https://docs.spring.io/spring-boot/reference/features/kotlin.html
- Spring Framework Kotlin:https://docs.spring.io/spring-framework/reference/languages/kotlin.html
- Dokka introduction:https://kotlinlang.org/docs/dokka-introduction.html
- Dokka Gradle:https://kotlinlang.org/docs/dokka-gradle.html
- Kotlin API guidelines introduction:https://kotlinlang.org/docs/api-guidelines-introduction.html
- Backward compatibility guidelines for library authors:https://kotlinlang.org/docs/api-guidelines-backward-compatibility.html
- API readability guidelines:https://kotlinlang.org/docs/api-guidelines-readability.html
- API consistency guidelines:https://kotlinlang.org/docs/api-guidelines-consistency.html
- API predictability guidelines:https://kotlinlang.org/docs/api-guidelines-predictability.html
内容风格¶
不是机械翻译¶
官方文档适合做权威参考,但中文学习者经常需要更多上下文。本仓库会保留官方知识结构,同时用中文重新组织解释。例如空安全不会只介绍 ?.、?:、!!,还会解释 Java 代码迁移时为什么会遇到平台类型,以及什么时候应该用空对象、默认值或提前返回。
保持 Kotlin 官方语义¶
如果官方文档明确规定某个行为,本仓库不改写语义。例如:
- Kotlin 普通类型默认非空,只有显式加
?才表示可空。 if和when都可以作为表达式使用。- 类默认是
final,继承需要显式open。 - Kotlin 集合区分只读接口和可变接口。
Java 对比只服务理解¶
Java 对比不是为了说 Kotlin “一定更好”,而是帮助有 Java 经验的读者建立迁移模型。对比会关注:
- 语法差异。
- 类型系统差异。
- 编译期检查与运行期行为。
- API 设计习惯。
- 与 Java 库互操作时的风险。
更新建议¶
每次补充或更新章节时,建议记录:
- 对照的官方页面链接。
- 官方页面最后更新时间。
- 当前文档新增了哪些中文解释或 Java 对比。
- 是否引入了 Kotlin 新版本特性。
不要为了追求“全文覆盖”而复制官方文档。更可维护的方式是按主题建立中文解释层,并在每章末尾提供官方参考链接。