Skip to content
skotch
...

Java/Kotlin Interop

Skotch produces standard Java 17 class files (major version 61). Compiled .class files run on any JVM that supports Java 17 or later.

Top-level Kotlin functions are compiled to static methods on a wrapper class named after the source file (e.g., main.ktMainKt). This matches the convention used by JetBrains’ kotlinc.

Terminal window
skotch emit --target jvm hello.kt -o HelloKt.class
java -cp . HelloKt

Skotch produces DEX v035 bytecode, compatible with Android API 13+. The output can be included in an APK and run on Android devices or emulators.

Skotch supports calling static methods on well-known Java classes directly:

fun main() {
val timestamp = System.currentTimeMillis()
println(timestamp)
println(Math.abs(-42)) // 42
println(Math.max(10, 20)) // 20
println(Integer.parseInt("123")) // 123
}

This also works in the REPL:

skotch> println(System.currentTimeMillis())
1744385123456

You can also use fully-qualified Java class names:

fun main() {
println(java.lang.System.getProperty("file.separator"))
println(java.lang.Math.random())
}

Explicit imports are supported:

import java.lang.Math
import java.lang.Integer
fun main() {
println(Math.abs(-42))
println(Integer.parseInt("123"))
}

java.lang.* is implicitly imported, matching Kotlin’s default imports.

ClassMethodsNotes
SystemcurrentTimeMillis(), nanoTime(), exit(Int), getProperty(String), getenv(String)java.lang.System
Mathabs(Int), max(Int,Int), min(Int,Int), random(), sqrt(Double), pow(Double,Double)java.lang.Math
IntegerparseInt(String), toString(Int), valueOf(Int)java.lang.Integer
LongparseLong(String)java.lang.Long
StringvalueOf(Int)java.lang.String
Threadsleep(Long)java.lang.Thread
FeatureStatus
Calling arbitrary Java librariesJDK classes resolved from jmod files; CLASSPATH JARs/dirs scanned
import package.ClassWorking — resolves class names for static calls
import package.*Parsed but classes not enumerated (hardcoded set only)
External dependency resolutionNot yet — Maven/Gradle deps ignored
Kotlin standard libraryNot bundled; println is a compiler intrinsic
ReflectionNot supported
AnnotationsNot yet compiled
  • Compiled .class files are valid Java bytecode and can be loaded by standard JVM tools (java, javap, jstack, etc.)
  • The REPL executes compiled code in an embedded JVM via JNI
  • Multiple Skotch-compiled files can call each other’s functions via invokestatic
  • Static method calls on System, Math, Integer, and String via invokestatic