Compilation 错误:无法找到或加载主类Hello.class

Compilation 错误:无法找到或加载主类Hello.class,compilation,jvm,runtime-error,kotlin,command-line-interface,Compilation,Jvm,Runtime Error,Kotlin,Command Line Interface,尽可能尝试最简单的kotlin hello world: thufir@dur:~/kotlin$ thufir@dur:~/kotlin$ ll total 32 drwxr-xr-x 2 thufir thufir 4096 Oct 27 07:28 ./ drwx------ 46 thufir thufir 16384 Oct 27 06:47 ../ -rw-r--r-- 1 thufir thufir 104 Oct 27 07:27 Hello.kt thufir@du

尽可能尝试最简单的kotlin hello world:

thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ ll
total 32
drwxr-xr-x  2 thufir thufir  4096 Oct 27 07:28 ./
drwx------ 46 thufir thufir 16384 Oct 27 06:47 ../
-rw-r--r--  1 thufir thufir   104 Oct 27 07:27 Hello.kt
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlinc Hello.kt 
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.intellij.util.text.StringFactory to constructor java.lang.String(char[],boolean)
WARNING: Please consider reporting this to the maintainers of com.intellij.util.text.StringFactory
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlin Hello.class 
error: could not find or load main class Hello.class
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ cat Hello.kt 
class Hello {



    fun main(args: Array<String>) {
        println("Hello, world!" + args[0])
    }
}
thufir@dur:~/kotlin$ 
thufir@dur:~/kotlin$ kotlinc -version
info: kotlinc-jvm 1.1.51 (JRE 9.0.0.15+181)
thufir@dur:~/kotlin$ 

首先,
Hello
可能不会像您预期的那样工作,因为它的
main
函数不是静态的。在Kotlin中,不需要类来定义
main
方法。只需使用功能:

fun main(args: Array<String>) {
    println("Hello, world!" + args[0])
}

首先,
Hello
可能不会像您预期的那样工作,因为它的
main
函数不是静态的。在Kotlin中,不需要类来定义
main
方法。只需使用功能:

fun main(args: Array<String>) {
    println("Hello, world!" + args[0])
}
$ ./compiler/kotlinc/bin/kotlin HelloKt test
Hello, world!test