Câu hỏi phỏng vấn Kotlin
Câu hỏi

What is the Kotlin double-bang !! operator?

Câu trả lời

The Kotlin double-bang !! operator is used to assert that a nullable value is not null and convert it to a non-nullable type[1][2][3]. It is also known as the "not-null assertion operator"[1][2].

When you use the double-bang operator on a nullable value, you are telling the compiler that you know for sure the value is not null and it is safe to access its properties or methods[1]. However, if the value is actually null, a NullPointerException will be thrown at runtime[1][2][3].

The double-bang operator should be used with caution, as it can lead to runtime exceptions if the value is unexpectedly null[3][4]. It is generally better to use null-safe calls with the safe call operator ?. or the Elvis operator ?:[3][4].

Here is an exampl...

middle

middle

Gợi ý câu hỏi phỏng vấn

senior

What is Kotlin backing field is used for?

middle

Explain advantages of when vs switch in Kotlin

middle

What are some disadvantages of Kotlin?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào