为什么Kotlin lang在项目中只允许一个主要功能? [英] Why does Kotlin lang allow only single main function in project?
问题描述
这不能消除Java中具有多个主入口点的功能,可以在需要时调用它们的原因.
Doesn't this take away the feature of having multiple main entry points in java which can be called as and when required.
推荐答案
更新:Kotlin的最新版本即使在同一软件包中(如果它们位于不同文件中)也允许多个main
函数.
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
不能在包中创建多个主要功能的原因是,包中的所有功能都存储在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
这篇关于为什么Kotlin lang在项目中只允许一个主要功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!