android-studio - 如何在 Android Studio 中运行 Kotlin 的控制台代码?
问题描述
我正在学习 Kotlin 的 Coroutines,许多示例代码如 Code A 在控制台下运行。
目前我必须在https://play.kotlinlang.org/上在线测试它,它太慢了。
如何在 Android Studio 中运行这些代码?
代码 A
import kotlinx.coroutines.*
fun main()=runBlocking{
val job = launch {
val child = launch {
try {
delay(Long.MAX_VALUE)
} finally {
println("1. Child is cancelled")
}
}
yield()
println("2. Cancelling child")
child.cancel()
child.join()
yield()
println("3. Parent is not cancelled")
}
job.join()
}
添加内容
谢谢!
但是当我运行代码时无法得到结果,我只得到信息“fun main(): Unit”!
解决方案
推荐阅读
- python - 使用 python (matplotlib) 复制 Stata 的 psgraph 的输出
- c# - 根据时间戳组织文件列表
- python - 如何使用 Python Selenium 在下拉菜单中激活复选框
- java - 混合 java 和 scala maven 项目不运行
- javascript - 数组元素未更新到与其先前状态相反的状态
- css - 选择器为真时的CSS条件设置
- websockify - 引发处理程序异常时退出 websockify
- sql - 无法向 COUNT 引入子查询
- javascript - clearInterval() 函数不会清除 React 中的 Interval
- terraform - 如何在 tf 模板中的条件语句中选择行?