SuperAPI AI Directory

kotlin

Data & analytics

View repository

Updated 10-15 20:32

About this skill

Kotlin

Null-safety and closed types win !!. Language first; Android UI: jetpack-compose / android-development. Real async: kotlin-coroutines.

Tooling

  • Kotlin 2.x / K2 in new code; respect kotlin in Gradle/version catalog.
  • kotlinc warnings handled in scope. kotlinOptions.jvmTarget aligned with the project's minSdk/JDK.
  • Style: ktlint / detekt if the repo already uses them.

Organization

src/main/kotlin/.../
  domain/
  data/            # se houver I/O
  • Packages by domain. internal for module API.
  • Prefer files by public type; avoid Utils.kt giant.
  • Top-level functions only for pure and stable helpers.

Language

  • val default; var only with a clear lifecycle.
  • data class for values; class for identity. value class for IDs.
  • sealed class / sealed interface for states (Loading / Ready / Err).
  • Exhaustive when without else blind on sealed.
  • Extensions for APIs that the type should not know about; not to hide side effects.
  • inline / reified only with real gain (not cosmetic).
  • Collections: listOf, buildList; mutable only when the contract requires it.
@JvmInline
value class UserId(val value: String)

sealed interface LoadState<out T> {
    data object Loading : LoadState<Nothing>
    data class Ready<T>(val value: T) : LoadState<T>
    data class Err(val reason: String) : LoadState<Nothing>
}

Null-safety

  • T? explicit. No !! except local invariant (Java platform type).
  • ?. / ?: / requireNotNull with message.
  • Java annotations (@Nullable) at JNI/SDK boundaries.

Functions and APIs

  • Default args > explosive overloads.
  • Named args in booleans (notify = false).
  • Result<T> or sealed error — one policy per boundary. Do not mix runCatching silent with domain exceptions.
  • typealias only when it clarifies; not to hide Pair<String, String>.

JVM / Android Interop

  • @JvmName / @JvmStatic / @JvmOverloads only in the API called from Java.
  • Do not expose Unit as a “magic void” in Java callbacks without documentation.
  • Coroutines on Android: viewModelScope — details in kotlin-coroutines.

Anti-patterns

  • Any / !! cascading
  • object singleton with global mutable state
  • Assume Compose/@Composable in this skill
  • apply/also/let unreadable nested
  • lateinit without init guarantee

Integration with other skills

  • Coroutines/Flow: kotlin-coroutines
  • Android app: android-development
  • Compose: jetpack-compose
  • Persistence: android-room
  • JVM tests: android-unit-testing

Completion criteria

  • Honest null-safety; sealed for states
  • APIs with clear defaults and named args
  • No !! unjustified
  • Formatted code; core tests if touched