This is more a matter of theory than a matter of solution, so listen to me.
In C / C ++, as well as PHP, you can declare constants. Usually there are several ways to do this ( #DEFINE for example, or " const type " ...), and the end result of this is that a replacement is performed at compile time, so that all these named constants become literals, This helps, because instead In order to have access to a memory cell for data search, the data is hard-coded, but without feedback from hard-coding - causing a value if it needs to be reused, and changing all instances of this value when it needs to be changed.
But the Java final declaration is a bit incomprehensible; because I can create a class with unset final vars and initialize them when building, that means they are not precompiled as literals, as far as I can tell. With the exception of ensuring that they cannot logically alter the afte construct, does the final declaration make any performance advantage?
Links to articles are in order, if you pay attention to the part that explains what final does, and what is, if there are any advantages, except for stopping the change of value after construction.
As a result, is it possible to declare compilation-level constants in Java in any other way than just using literals (in any case, a bad idea?)
user1086498
source share