← 返回
开发者工具 中文

Kotlin

Build robust Android and multiplatform apps with Kotlin idioms, coroutines, and null safety.
使用 Kotlin 惯用法、协程和空安全打造健壮的 Android 与跨平台应用。
ivangdavila
开发者工具 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 3
Stars
📥 2,136
下载
💾 73
安装
1
版本
#latest

概述

Quick Reference

TopicFile
-------------
Null safety operators and patternsnullsafety.md
Coroutines, flows, structured concurrencycoroutines.md
Collections, sequences, data classescollections.md
Scope functions, extensions, sealed classesidioms.md
Java interop and common Kotlin mistakesinterop.md
Android lifecycle, Compose stateandroid.md
Delegation, inline, reified, multiplatformadvanced.md

Critical Rules

Null Safety

  • !! asserts non-null — crashes on null, use only when you've already checked
  • Platform types from Java are risky — add null checks or use @Nullable/@NonNull annotations
  • Elvis with return/throw for early exit — val name = user?.name ?: return

Coroutines

  • viewModelScope auto-cancels on ViewModel clear — don't use GlobalScope in Android
  • Structured concurrency: child coroutine failure cancels parent — use supervisorScope to isolate
  • StateFlow needs initial value and never completes — SharedFlow for one-shot events
  • Inject dispatchers for testability — don't hardcode Dispatchers.IO

Collections & Data Classes

  • first() throws on empty — use firstOrNull() for safe access
  • Only constructor properties in equals/hashCode — body properties ignored
  • mutableStateListOf for Compose — wrapping mutableListOf in state won't track changes

Scope Functions & Extensions

  • Don't nest scope functions — readability drops fast, extract to named functions
  • Extensions are resolved statically — not polymorphic, receiver type matters at compile time

Android/Compose

  • repeatOnLifecycle(STARTED) for flow collection — launchWhenStarted is deprecated
  • remember survives recomposition only — use rememberSaveable for config changes
  • collectAsStateWithLifecycle is the gold standard — lifecycle-aware + Compose state

Java Interop

  • == is structural equality in Kotlin — === for reference, opposite of Java
  • SAM conversion only for Java interfaces — Kotlin interfaces need explicit fun interface
  • @JvmStatic, @JvmOverloads, @JvmField for Java-friendly APIs

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-03-28 22:20 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 68 📥 180,546
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,363 📥 319,196
developer-tools

Gog

steipete
Google Workspace 命令行工具,支持 Gmail、日历、云端硬盘、通讯录、表格和文档。
★ 921 📥 185,946