kotlin-java-library
Kotlin Java Library Design
Quick start
- Design Kotlin APIs as if the primary caller is Java: explicit overloads, stable names, and predictable nullability.
- Use JVM interop annotations (
@JvmOverloads,@JvmStatic,@JvmField,@JvmName) to shape the Java surface. - Prefer Java-friendly top-level functions with
@file:JvmName, and use@file:JvmMultifileClasswhen splitting across files. - Use
fun interfacefor Java callbacks; avoid function types that returnUnit. - Document checked exceptions with
@Throwsand return defensive copies for read-only collections. - Follow binary compatibility rules; add overloads instead of changing signatures.
- Read
references/kotlin-java-library.mdfor examples, recipes, and checklists.
Workflow
- Identify which public APIs must be Java-friendly (constructors, factories, utilities).
- Shape the Java surface with JVM annotations and explicit overloads.
- Audit public signatures for Java stability (names, nullability, overload sets, and collection exposure).
- Apply backward-compatibility rules before publishing.
- Validate with Java call-site examples.
Rules of thumb
- Avoid Kotlin-only surface features in public API: default args without overloads, extension-only entry points, and name clashes.
- Use
@JvmOverloadsfor Java-callable optional parameters, and provide explicit overloads when behavior differs. - Use
@JvmStaticfor companion/object members meant to be static in Java. - Use
@JvmFieldonly for constants or immutable fields you want exposed as fields. - Use
@JvmNameto resolve signature clashes or to provide a stable Java name. - Avoid
Nothingin public generic signatures; it becomes raw types in Java.
Output expectations
- Offer Java-call-site examples when proposing API changes.
- Call out binary compatibility risks and safer alternatives.
References
- Load
references/kotlin-java-library.mdfor interop details, examples, and testing prompts.
More from alexandru/skills
cats-effect-io
Scala functional programming with Cats Effect IO and typeclasses. Use for wrapping side effects, modeling purity, choosing Sync/Async/Temporal/Concurrent, handling blocking I/O, and composing resources, fibers, and concurrency safely.
39cats-effect-resource
Scala resource lifecycle management with Cats Effect `Resource` and `IO`. Use when defining safe acquisition/release, composing resources (including parallel acquisition), or designing resource-safe APIs and cancellation behavior for files, streams, pools, clients, and background fibers.
36cats-mtl-typed-errors
Scala typed errors with Cats MTL Raise/Handle and allow/rescue. Use for designing custom domain error types without EitherT, while keeping Cats Effect and ecosystem composition. Covers Scala 2/3 syntax and IO-only or F[_] usage.
23akka-streams
Scala reactive streaming with Akka Streams and Pekko Streams. Use for dataflow and reactive programming patterns, testing stream components, and understanding when NOT to use streams (prefer plain functions for transformations and I/O).
20arrow-typed-errors
Kotlin + Arrow typed error handling using Raise DSL and wrapper types (Either/Option/Ior/Result/nullable), including validation with accumulation, interop with exceptions, and custom error wrappers. Use for designing or refactoring error modeling, converting exception-based flows, building smart constructors, accumulating validation errors, or integrating Outcome/Progress-style wrappers with Arrow.
16jspecify-nullness
JSpecify nullness annotations for Java APIs and tooling. Use when adopting or migrating JSpecify annotations, designing null-safe Java signatures and generics, or interpreting tool conformance and Kotlin interop.
13