java - 无法在 Kotlin 中使用协程(未解决的参考)
问题描述
我创建了 gradle java kotlin 项目。我想使用协程,但我得到了unresolved reference launch
错误unresolved reference delay
:
import java.util.*
import kotlinx.coroutines.*
fun main (args: Array<String>)
{
launch { // launch coroutine
delay(1000L)
println("World!")
}
println("Hello")
}
在 build.gradle.kts 中,我将这一行包含在依赖项块中:
implementation("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.5.2")
编辑:
我的 build.gradle.kts 文件:
plugins {
kotlin("jvm") version "1.5.10"
java
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
EDIT2:清除缓存后一切都修复了。您可以在 File-> Invalidate caches 中执行此操作
解决方案
推荐阅读
- android - 自定义键盘上的字母键模糊,而特殊键超级清晰
- pointers - `go print(v)` 和 `go func() { print(v) }()` 之间的区别?
- android - this.refs 返回未定义的值
- html - 如何在文档中嵌入作用域 html (css)
- ios - 在 Objective-C 中调用 swift 视图控制器文件的变量
- batch-file - 如何在没有其他文件夹的情况下批量复制文件夹内的文件?
- redis - Jedis 在 Redis 中有多个哨兵时表现异常
- tensorflow - 在视频上使用带有 LSTM 的 TensorFlow 对象检测 API
- c# - 无法使用 c# 客户端连接 docker aerospike 服务器
- android - 如何从资产 android (API 21+) 播放 swf 文件?