为什么Array< String>在Kotlin中为主要功能选择的参数类型? [英] Why is Array<String> the chosen parameter type for the main function in kotlin?
本文介绍了为什么Array< String>在Kotlin中为主要功能选择的参数类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
kotlin的主要功能:
The main function in kotlin:
fun main(args : Array<String>) {
println("Hello, world!")
}
为什么要传入数组?
推荐答案
The signature of main
is based on what the Java Virtual Machine expects:
必须将方法
main
声明为public, static, and void
.它必须指定一个声明的类型为字符串数组的形式参数(第8.4.1节).因此,可以使用以下任何一种声明:
The method
main
must be declaredpublic, static, and void
. It must specify a formal parameter (§8.4.1) whose declared type is array of String. Therefore, either of the following declarations is acceptable:
public static void main(String[] args)
public static void main(String... args)
这是Kotlin编译器将您的主要功能编译到的内容.从Kotlin 1.3开始,显式的Array<String>
可以省略,但在字节码中仍然可用.
This is what the Kotlin compiler compiles your main function to. As of Kotlin 1.3, the explicit Array<String>
can be omitted but will still be available in the byte code.
这篇关于为什么Array< String>在Kotlin中为主要功能选择的参数类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文