“?”的名字是什么? operator/symbol in "var button: Button? = null" Kotlin 表达式?
What is the name of "?" operator/symbol in "var button: Button? = null" expression in Kotlin?
我们可以通过在变量类型末尾使用?
运算符来定义一个考虑是否可以存储空值的变量,例如var button: Button? = null
.
我知道当我们使用 button 变量时,我们必须使用安全调用运算符 ?.
,但这与我们在var button: Button? = null
现在,这个 ?
运算符应该怎么发音?
我将其称为“nullable/nullability 运算符”。在 documentation 中,您会找到一些对它的引用(与其他运算符相关联,例如 as
),尽管它可能没有正式名称.
"Safe" (nullable) cast operator
在文档的 Keyworks and Operators 部分,您会找到对它的引用:
? marks a type as nullable
我们可以通过在变量类型末尾使用?
运算符来定义一个考虑是否可以存储空值的变量,例如var button: Button? = null
.
我知道当我们使用 button 变量时,我们必须使用安全调用运算符 ?.
,但这与我们在var button: Button? = null
现在,这个 ?
运算符应该怎么发音?
我将其称为“nullable/nullability 运算符”。在 documentation 中,您会找到一些对它的引用(与其他运算符相关联,例如 as
),尽管它可能没有正式名称.
"Safe" (nullable) cast operator
在文档的 Keyworks and Operators 部分,您会找到对它的引用:
? marks a type as nullable