Why does Kotlin lang allow only single main function in project?

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!")
    }
}

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

Tags:

Kotlin