我在理解下面的代码时遇到一些困难:
fun helperMethodNameA(someId: String, rules: RulesObject) {
val content = JsonNodeFactory.instance.arrayNode().apply { // A & B
add(JsonNodeFactory.instance.objectNode().apply {
set("body", JsonNodeFactory.instance.objectNode().apply { // C
set("text", JsonNodeFactory.instance.objectNode().apply { // D
set("value", JsonNodeFactory.instance.textNode(mapper.writeValueAsString(rules))) // E
})
})
})
}
return helperMethodNameB(someId, content.toString())
}
该项目依赖于另一个版本,该版本设置了Kotlin v1.3.20。依赖项项目将Kotlin版本提高到v1.3.60。按照以下内容,此位中断了更新:
A - [ERROR] <pathToFile> [line, position] Type inference failed: inline fun <T> T.apply(block: T.() -> Unit): T
[ERROR] cannot be applied to
[ERROR] receiver: ArrayNode! arguments: (ArrayNode!.() -> ArrayNode!)
B - [ERROR] <pathToFile> [line, position] Type mismatch: inferred type is ArrayNode!.() -> ArrayNode! but ArrayNode!.() -> Unit was expected
C - [ERROR] <pathToFile> [line, position] Type inference failed: Not enough information to infer parameter T in operator fun <T : JsonNode!> set(p0: String!, p1: JsonNode!): T!
[ERROR] Please specify it explicitly.
D - [ERROR] <pathToFile> [line, position] Type inference failed: Not enough information to infer parameter T in operator fun <T : JsonNode!> set(p0: String!, p1: JsonNode!): T!
[ERROR] Please specify it explicitly.
E - [ERROR] <pathToFile> [line, position] Type inference failed: Not enough information to infer parameter T in operator fun <T : JsonNode!> set(p0: String!, p1: JsonNode!): T!
[ERROR] Please specify it explicitly.
我在这里想念什么?
fun helperMethodNameA(someId: String, rules: RulesObject) {
val content = JsonNodeFactory.instance.arrayNode().apply {
add(JsonNodeFactory.instance.objectNode().apply {
set<ObjectNode>("body", JsonNodeFactory.instance.objectNode().apply {
set<ObjectNode>("text", JsonNodeFactory.instance.objectNode().apply {
set<TextNode>("value", JsonNodeFactory.instance.textNode(mapper.writeValueAsString(rules)))
})
})
})
}
return helperMethodNameB(someId, content.toString())
}