首页 > 解决方案 > Run single Kotlin file

问题描述

I have two Kotlin files in the same folder:

enter image description here

Both files have a trivial main method. I can right click on helloworld.kt file and select "Run..." from the menu. There's no such option for the circle.kt file though.

This is my run/debug configuration for helloworld.kt: enter image description here

I tried to create an equivalent configuration for circle.kt, but it complains that the class com.example.kotlin.learning.CircleKt has no main method:

enter image description here

There's actually no class in that file. But there isn't one in HelloWorld.kt as well, and that works.

Here's the code for helloworld.kt:

package com.example.kotlin.learing


fun main (argomenti: Array<String>) {
    println ("SUCA!")
    println (saluta ( "mario"))

    val vettore : Array<String> = arrayOf("pippo", "pluto", "paperino")
    println(vettore [0])
}

fun saluta (chi : String) = ( chi + " antani" )

here's circle.kt:

package com.example.kotlin.learing



fun main() = println("pippuz!")

I realize I am missing something deep here. What is that? Thanks

标签: intellij-ideakotlin

解决方案


如果我没记错的话,Kotlin 版本 1.3-RCmain支持不带参数的方法。您使用的是哪个版本的 Kotlin?

如果你使用的是旧版本的 Kotlin,你应该传递一个字符串数组作为main方法的参数。


推荐阅读