language-kotlinlisted
Install: claude install-skill lugassawan/swe-workbench
# Kotlin
## Null safety
- `?` makes nullability explicit in the type — `String?` vs `String`.
- Safe-call `?.` returns null instead of throwing. Elvis `?:` provides a default.
- **Never use `!!` in production code** — it is a promise you will never break that can't be verified.
- Jackson does not null-check collection *elements* even with `jackson-module-kotlin` — a declared
`List<Content>` can hold nulls from `{"content":[null]}`. Use `filterNotNull()` (not
`filter { it != null }`, which leaves the type as `List<Content?>`), or
`@JsonSetter(contentNulls = Nulls.SKIP)` at the boundary.
```kotlin
val length = name?.trim()?.length ?: 0
user?.email?.let { send(it) } // null-guard + scoping
val ids = payload.content.filterNotNull().map { it.id }
```
## Data classes and sealed interfaces
- `data class` for value containers: auto-generates `equals`, `hashCode`, `toString`, `copy`, and destructuring.
- `sealed interface` closes a hierarchy and enables exhaustive `when` without an `else` branch.
```kotlin
sealed interface Result<out T>
data class Success<T>(val value: T) : Result<T>
data class Failure(val error: Throwable) : Result<Nothing>
fun handle(r: Result<User>) = when (r) {
is Success -> show(r.value)
is Failure -> log(r.error)
}
```
## Coroutines — structured concurrency
- `suspend` functions must be called from a coroutine or another `suspend` function.
- Use `coroutineScope { }` for fan-out — child coroutines are cancelled if one fails.
- `withContext(