加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Kotlin Native等效于System.exit(-1)

发布时间:2020-12-15 04:41:18 所属栏目:Java 来源:网络整理
导读:在下面的Kotlin / JVM程序中,System.exit(-1)使用错误退出代码停止程序的执行: fun main(args: ArrayString) { if (args.size 2) { println("too few args!") System.exit(-1) } println("Hello,${args[1]} from ${args[0]}")} Kotlin / Native无权访问任何
在下面的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程序使用错误代码停止执行程序的等效函数是什么?

解决方法

使用exitProcess:

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

Declaration and documentation在Kotlin源代码中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读