java Kotlin系统的本机等价物。出口(1)
在以下Kotlin/JVM程序中System.exit(-1)
使用错误退出代码停止程序的执行:
fun main(args: Array<String>) {
if (args.size < 2) {
println("too few args!")
System.exit(-1)
}
println("Hello, ${args[1]} from ${args[0]}")
}
Kotlin/Native无权访问任何Java类,包括System
。那么,对于Kotlin/本机程序来说,用一个错误代码停止程序执行的等效函数是什么呢
# 1 楼答案
使用
exitProcess
:Declaration and documentation在Kotlin源代码中