Woops, your right. I was 100% sure that it would not create any fields. In that case this will only get inlined by the kotlin compiler and it can still be accessed by java. In that case I would agree, an annotation would maybe be better.
There is still one important difference between const val
and val
which I guess is the reason to make it a keyword.
val foo1 = 42
const val foo2 = 43
println(foo1) => println(foo)
println(foo2) => println(43)
This is still true, if you define foo2 in a different library. This means you can not use const
inside of a library and change it later. Any kotlin program using the library would need to be recompiled to access it.
Oh, yeah and I tested it this time instead answering from memory