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

junior

Where should I use var and where val ?

junior

What is the idiomatic way to remove duplicate strings from array?

middle

May you briefly compare Kotlin vs Java?

Bình luận

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

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