我尝试使用 Kotlin 构建一个简单的应用程序,该应用程序在 GraalVM 本机映像上使用 kotlin.random.Random 类。但这在运行时失败了。堆栈跟踪见下文。
作为解决方法,您可以使用 java 标准 java.util.Random 类。
有人可以告诉我如何使用 Kotlin 类型吗?
应用程序.kt
import kotlin.random.Random
fun main(args: Array<String>) {
println(Random.nextInt())
}
Run Code Online (Sandbox Code Playgroud)
Dockerfile
############################################################################
# Graal Native Image Early-Access Build
#
# Make sure you configured Docker to use at least 6gb ram!
# build from project root dir with: docker build -t example-kotlin-random-graalvm-native:1.0.0-SNAPSHOT .
# run with: docker run -d example-kotlin-random-graalvm-native:1.0.0-SNAPSHOT
############################################################################
#####
# The builder image to build the native app
#####
FROM findepi/graalvm:native as builder …Run Code Online (Sandbox Code Playgroud)