What is the difference between “const” and “val”?

前端 未结 7 2077
既然无缘
既然无缘 2020-12-22 17:20

I have recently read about the const keyword, and I\'m so confused! I can\'t find any difference between const and the val keyword, I

7条回答
  •  时光说笑
    2020-12-22 18:07

    Just to add to Luka's answer:

    Compile-Time Constants

    Properties the value of which is known at compile time can be marked as compile time constants using the const modifier. Such properties need to fulfill the following requirements:

    • Top-level or member of an object declaration or a companion object.
    • Initialized with a value of type String or a primitive type
    • No custom getter

    Such properties can be used in annotations.

    Source: Official documentation

提交回复
热议问题