为什么Kotlin lang在项目中只允许一个主要功能? [英] Why does Kotlin lang allow only single main function in project?

查看:74
本文介绍了为什么Kotlin lang在项目中只允许一个主要功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不能消除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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆