swift4j maps Swift types to their JVM equivalents automatically. The tables below show the mapping for each supported category.
| Swift | Kotlin | Java |
|---|
Bool | Boolean | boolean |
Int | Long | long |
Int32 | Int | int |
Int16 | Short | short |
Int8 | Byte | byte |
UInt8 | Byte | byte |
Float | Float | float |
Double | Double | double |
Int maps to Long because Swift’s Int is 64-bit on all platforms swift4j targets.
| Swift | Kotlin | Java |
|---|
String | String | String |
| Swift | Kotlin | Java |
|---|
[Int] | LongArray | long[] |
[Double] | DoubleArray | double[] |
[Float] | FloatArray | float[] |
[Bool] | BooleanArray | boolean[] |
[String] | Array<String> | String[] |
[T] where T is @jvm | Array<T> | T[] |
| Swift | Kotlin | Java |
|---|
T? where T is a class | T? | @Nullable T |
Int? | Long? | Long (boxed) |
String? | String? | @Nullable String |
(() -> Void)? | (() -> Unit)? | @Nullable Runnable |
| Swift | Kotlin | Java |
|---|
() -> Void | () -> Unit | Runnable |
(T) -> Void | (T) -> Unit | Consumer<T> |
(T) -> R | (T) -> R | Function<T, R> |
(T, U) -> R | (T, U) -> R | BiFunction<T, U, R> |
All types in the closure signature must be mapped types or @jvm-annotated types.
| Swift | Kotlin / Java |
|---|
async func f() -> T | CompletableFuture<T> |
async func f() throws -> T | CompletableFuture<T> (exception in future) |
Classes, structs, and enums annotated with @jvm map to their generated proxy class by name. The package is the target name (hyphens replaced with underscores).
| Swift | Kotlin |
|---|
@jvm class Foo | MyTarget.Foo |
@jvm struct Bar | MyTarget.Bar |
@jvm enum Baz (no assoc. values) | MyTarget.Baz (enum) |
@jvm enum Baz (with assoc. values) | MyTarget.Baz (sealed class) |
Types not listed above cannot be exported. Attempting to use them in an exported method signature causes a compiler warning from @jvm. Use @nonjvm to suppress the warning for members that intentionally use unexportable types.