简体   繁体   English

kotlin IntelliJ IDEA 主函数不返回任何内容

[英]kotlin IntelliJ IDEA main function not returning anything

I am trying to learn Kotlin.我正在尝试学习 Kotlin。 While working my way through Kotlin Bootcamp for Programmers by Google I have encountered an issue with functions.在通过 Google 的 Kotlin Bootcamp for Programmers 工作时,我遇到了函数问题。

A simple Hello World function that I have added in separate kotlin script when ran does not return anything.我在运行时在单独的 kotlin 脚本中添加的一个简单的 Hello World 函数不返回任何内容。

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

ScreenShot截屏

In addition I am getting warning: WARNING: Illegal reflective access by com.intellij.util.ReflectionUtil此外,我收到警告:警告:com.intellij.util.ReflectionUtil 的非法反射访问

I was able to find solution which requires adding following line to gradle.properties but it seems not to work.我能够找到需要将以下行添加到 gradle.properties 的解决方案,但它似乎不起作用。 org.gradle.jvmargs=-Dkotlin.daemon.jvm.options=--illegal-access=permit org.gradle.jvmargs=-Dkotlin.daemon.jvm.options=--illegal-access=permit

Project JDK is coretto-15, IntelliJ IDEA is up to date.项目 JDK 是 coretto-15,IntelliJ IDEA 是最新的。 I am also curious why kotlin files have .kts extension while everywhere I look it says it should be .kt我也很好奇为什么 kotlin 文件有 .kts 扩展名,而我到处看它都说它应该是 .kt

You need to create the Kotlin sources under the src/main/kotlin directory.您需要在src/main/kotlin目录下创建 Kotlin 源代码。 But you have created in under the src directory, which is not the source root.但是你已经在src目录下创建了,它不是源根目录。 See alsoKotlin and Java sources.又见科特林和Java源代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM