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

What is the difference between const and val ?

Câu trả lời

Here is the difference between const and val in Kotlin:

const

  • const is a modifier that can only be applied to properties declared as val (immutable).
  • const properties must be of type String or primitive type (Int, Long, Byte, Short, Char, Boolean, Double, Float).
  • const properties must be initialized with a compile-time constant value.
  • const properties are inlined at compile-time, meaning their values are replaced directly in the code where they are used.
  • const properties are resolved at compile-time and cannot be changed at runtime.

val

  • val is a keyword used t...
middle

middle

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

middle

How are extensions resolved in Kotlin and what doest it mean?

middle

When would you use Elvis operator in Kotlin?

middle

Explain lazy initialization in Kotlin

Bình luận

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

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