以下是 Kotlin 代码:
val x = null + null
x
的类型为 String
是正确的,因为根据 String.plus
的文档:
将此字符串与给定 [other] 对象的字符串表示连接起来。 如果接收器或 [other] 对象中的任何一个为 null,则它们将表示为字符串 "null"。
然而,我不明白为什么会这样 - 这是由于语言的某些特殊功能吗?
null.plus(null)
,然后当你切换到该方法时,你就能够读取注释了。 - Morozovplus()
运算符。在这里:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/plus.html - Mauker