spotbugs 与 Kotlin 兼容吗?
Is spotbugs compatible with Kotlin?
当 运行 在 Kolin 项目上发现错误时,我得到如下错误:
[ERROR] Private method com.example.CSVRecord.component1() is never called [com.example.CSVRecord] In CSVRecord.kt UPM_UNCALLED_PRIVATE_METHOD
在 类 例如:
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(...)
当 运行 在 Kolin 项目上发现错误时,我得到如下错误:
[ERROR] Private method com.example.CSVRecord.component1() is never called [com.example.CSVRecord] In CSVRecord.kt UPM_UNCALLED_PRIVATE_METHOD
在 类 例如:
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(...)