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
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