Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 515
ice1000 Avatar asked May 25 '17 00:05

ice1000


1 Answers

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

like image 94
gildor Avatar answered Oct 01 '22 08:10

gildor