【问题标题】:Kotlin Native equivalent of System.exit(-1)相当于 System.exit(-1) 的 Kotlin Native
【发布时间】:2018-05-16 04:50:15
【问题描述】:

在以下 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/Native 程序停止执行带有错误代码的程序的等效函数是什么?

【问题讨论】:

  • 我猜你可以在 C 中正常使用 exit 函数。

标签: java kotlin native kotlin-native


【解决方案1】:

使用exitProcess:

import kotlin.system.exitProcess
...
exitProcess(exitCode)

Declaration and documentation 在 Kotlin 源代码中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 2019-02-08
    相关资源
    最近更新 更多