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

What is lateinit in Kotlin and when would you use it?

senior

What are Object expressions in Kotlin and when to use them?

expert

What is a motivation to make classes final by default in Kotlin? Do you agree with that decision?

Bình luận

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

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