kotlin-patterns
Idiomatic Kotlin patterns, best practices, and conventions for building robust, efficient, and maintainable Kotlin applications, including coroutines, null safety, and DSL builders.
Machine translationRead the original Chinese text
惯用的Kotlin模式、最佳实践和约定,用于构建健壮、高效且可维护的Kotlin应用程序,包括协程、空安全和DSL构建器。
Target: Target not categorized. Automatically collected · unverified.
Excerpt from the author’s documentation
Extracted from a fixed version of SKILL.md in its original language. This is the author’s documentation; installation, compatibility and runtime results have not been verified by this site.
Read the original Chinese text
Topics in the source
- Kotlin 开发模式
- 使用时机
- 工作原理
- 示例
- 核心原则
- 1. 空安全
- 2. 默认不可变性
- 3. 表达式体和单表达式函数
适用于构建健壮、高效、可维护应用程序的惯用 Kotlin 模式与最佳实践。 编写新的 Kotlin 代码 审查 Kotlin 代码 重构现有的 Kotlin 代码 设计 Kotlin 模块或库 配置 Gradle Kotlin DSL 构建 本技能在七个关键领域强制执行惯用的 Kotlin 约定:使用类型系统和安全调用运算符实现空安全;通过数据类的 val 和 copy() 实现不可变性;使用密封类和接口实现穷举类型层次结构;使用协程和 Flow 实现结构化并发;使用扩展函数在不使用继承的情况下添加行为;使用 @DslMarker 和 lambda 接收器构建类型安全的 DSL;以及使用 Gradle Kotlin DSL 进行构建配置。 使用 Elvis 运算符实现空安全: 使用密封类处理穷举结果: 使用 async/await 实现结构化并发: Kotlin 的类型系统区分可空和不可空类型。充分利用它。 优先使用 val 而非 var,优先使用不可变集合而非可变集合。 使用表达式体编写简洁、可读的函数。 使用数据类表示主要包含数据的类型。 | 惯用法 | 描述 | |-------|-------------| | val 优于 var | 优先使用不可变变量 | | data class | 用于具有 equals/hashCode/copy 的值对象 | | sealed class/interface | 用于受限的类型层次结构 | | value class | 用于零开销的类型安全包装器 | | 表达式 when | 穷举模式匹配 | | 安全调用 ?. | 空安全的成员访问 | | Elvis ?: | 为可空类型提供默认值 | | let/apply/also/run/with | 用于编写简洁代码的作用域函数 | | 扩展函数 | 在不使用继承的情况下添加行为 | | copy() | 数据类上的不可变更新 | | require/check | 前置条件断言 | | 协程 async/await | 结构化并发执行 | | Flow | 冷响应式流 | | sequence | 惰性求值 | | 委托 by | 在不使用继承的情况下重用实现 | 请记住:Kotlin 代码应简洁但可读。利用类型系统确保安全,优先使用不可变性,并使用协程处理并发。如有疑问,让编译器帮助你。
- Source repository
- affaan-m/ECC
- Source file
- docs/zh-CN/skills/kotlin-patterns/SKILL.md
- Fixed revision
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
Requirements
- Only the author’s Skill metadata is included. Read the full instructions to check dependencies, licensing and conditions of use.
A small first task
先阅读原作者说明,再决定是否在自己的 AI 工具中使用。
Instructions for your AI tool
- Claude Desktop: resource-specific guide not available yet
- Claude Code: resource-specific guide not available yet
- Cursor: resource-specific guide not available yet
- Codex: resource-specific guide not available yet
Author documentation is not live verification by this site. Without evidence, we do not mark a resource as compatible, safe or free.
Sources and evidence
This record was collected automatically. Its documentation, suitability and runtime behavior have not been manually verified.
Author: affaan-m/ECC · original repository metadata. Documentation review: Not reviewed. Last source check: 2026-11-09T15:01:42.407Z.
Categories are inferred from names, descriptions and paths. They do not establish compatibility.
License and attribution
MIT. Third-party content and copyright remain with their authors. Refer to the original license and terms.
Original license ↗Synchronization, copying and user-reported success do not mark a resource as runtime-tested.
Limitations and notes
- Collecting metadata does not mean this site has installed, adapted, runtime-tested or security-reviewed the resource.