gpt4 book ai didi

kotlin - Spotbug是否与Kotlin兼容?

转载 作者:行者123 更新时间:2023-12-02 13:23:16 25 4
gpt4 key购买 nike

在Kolin项目上运行Spotbug时,出现如下错误:

[ERROR] Private method com.example.CSVRecord.component1() is never called [com.example.CSVRecord] In CSVRecord.kt UPM_UNCALLED_PRIVATE_METHOD



在以下类(class)上:
data class CSVRecord(private val columns: SortedSet<CSVColumn>) : Iterable<String> {

override fun iterator(): Iterator<String> {
return columns.map { it.value }.iterator()
}
}

我不清楚 component1的来源!

最佳答案

根据Data Classes文档:

The compiler automatically derives the following members from all properties declared in the primary constructor:

  • equals()/hashCode() pair;
  • toString() of the form "User(name=John, age=42)";
  • componentN() functions corresponding to the properties in their order of declaration;
  • copy() function (see below).


这是数据类的功能之一。自动生成的 componentN函数允许您在以下类型的类上使用 Destructuring Declarations:
data class Result(val result: Int, val status: Status)
fun function(...): Result {
// computations

return Result(result, status)
}

// Now, to use this function:
val (result, status) = function(...)

关于kotlin - Spotbug是否与Kotlin兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50451801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com