我正在尝试@Serializable在 Kotlin 中使用注释。我可以使用 Gradle 构建项目,但它在 IntelliJ 中显示为红色,当我将鼠标悬停在@Serializable注释上时,会显示一条消息:
kotlinx.serializable compiler plugin is not applied to the module, so this
annotation would not be processed. Make sure you've setup your buildscript
correctly and re-import project.
Run Code Online (Sandbox Code Playgroud)
我的build.gradle.kts文件看起来像这样:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3.50")
id("org.jetbrains.kotlin.plugin.serialization") version "1.3.50"
idea
}
repositories {
jcenter()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(group = "com.charleskorn.kaml", name = "kaml", version = "0.12.0")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
Run Code Online (Sandbox Code Playgroud)
我安装了最新版本的 Kotlin 插件 (1.3.50)。
如果我将 Magritte 摄取设置为追加,它会检测源数据中是否删除了行吗?它还会删除摄取数据集中的行吗?
假设我们有一个整数列表:1, 2, 5, 13, 6, 5, 7我想找到第一个重复的数字并返回两个索引的向量。在我的示例中,它是 5 at [2, 5]。到目前为止我所做的是loop,但我可以做得更优雅、更短吗?
(defn get-cycle
[xs]
(loop [[x & xs_rest] xs, indices {}, i 0]
(if (nil? x)
[0 i] ; Sequence is over before we found a duplicate.
(if-let [x_index (indices x)]
[x_index i]
(recur xs_rest (assoc indices x i) (inc i))))))
Run Code Online (Sandbox Code Playgroud)
不需要返回数字本身,因为我可以通过索引获取它,其次,它可能并不总是存在。