why does `const` need to be specified explicitly? ...
# announcements
l
why does
const
need to be specified explicitly? can't the compiler check automatically if the keyword is applicable ? or is there a scenario where you wouldn't want its optimizations ?
a
const
gets compiled into call sites. If you're writing a library, the value of
const
properties is part of your binary compatibility contract and you can't change the values of those constants across versions without breaking other compiled code
👆 2
l
ty
c
Also, the JVM is more or less able to inline stuff at runtime anyway, so not using
const
shouldn't be too much of a difference
m
CONSTants are “deeply” immutable - use them for things which are not only immutable, but will NEVER change.