What's the difference between !! and ? in Kotlin?

后端 未结 6 1304
情深已故
情深已故 2020-12-04 14:15

I am new to Kotlin. I want to know the difference between this two !! and ? in below code.

Below, there are two snippets: the first uses

6条回答
  •  伪装坚强ぢ
    2020-12-04 14:34

    this is '!!' double-bang operator is always return not-null value and this is '?' safe call operator returns value if value is not null, and null otherwise

    This is unsafe nullable type (T?) conversion to a non-nullable type (T). It will throw NullPointerException if the value is null.

    It is documented here along with Kotlin means of null-safety.

    ref - hotkey

提交回复
热议问题