Doesn't this take away the feature of having multiple main entry points in java which can be called as and when required.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
UPDATE: recent versions of Kotlin allow multiple main
functions even in the same package (if they are in different files).
You can have multiple main functions in your project but only one main function per package
The reason why you can't make multiple main functions in package is that all functions in package are stored in Package class so you can't have multiple functions in a class with same signatures.
So if you want multiple main functions you have to define them in different packages
回答2:
In addition to Sergey Mashkov's comment: you can put a main
inside an object and mark it @JvmStatic
:
object Main {
@JvmStatic
fun main(args: Array<String>) {
println("Hello, world!")
}
}