kotlin-java-library
4
总安装量
2
周安装量
#53089
全站排名
安装命令
npx skills add https://github.com/alexandru/skills --skill kotlin-java-library
Agent 安装分布
replit
2
amp
2
opencode
2
kimi-cli
2
github-copilot
2
Skill 文档
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.