ice1000
ice1000

Reputation: 6579

Why IntelliJ doesn't recognize my main method?

I have:

fun Array<String>.main() {
  println("Hello World")
}

I can compile and run it with 'java main.Main -cp [kotlin-runtime]' but in IntelliJ there isn't a 'run' button, and I cannot select this file as a main file.

Edit

It's now correctly recognized by IntelliJ since Kotlin 1.1.5.

Upvotes: 7

Views: 3435

Answers (2)

ice1000
ice1000

Reputation: 6579

Oh yeah, there's only two kinds of main method can be identified by IntelliJ:

fun main(args: Array<String>) {
}
fun main(vararg args: String) {
}

Upvotes: 0

gildor
gildor

Reputation: 1894

You should use top-level main function instead

fun main(args: Array<String>) {
    println("Hello World")
}

Extension function (with any name) for array doesn't work as main method

Upvotes: 10

Related Questions