First, in my opinion Java has no constant, has static fields that can not have their value changed after defined, which is static will always occur before being accessed the first. I don’t know if Java has any specification that indicates the exact timing of the assignment. So for me the term constant can’t even be used in the case shown in the question, it’s a static variable immutable.
In C# there is immutable variable, static or not and constant that is always static and guaranteed to be the same in every execution (if the programmer does not shave and use constant as if it were immutable variable). Of course constant must be solved at compile time always, it cannot be initialized after, so not all types can be used.
If that doesn’t answer the question as I would wish, then I would say that a type by reference, called in the question of not primitive*, placed in a variable final
, that makes it immutable, could be called constant, regardless of whether it is static or not, after all if the term is used wrong in static variables, I do not see why not use in instance variables. So it would be the value indicated by that identifier, which is the reference for an object is "constant", but the object pointed by it can be variable.
Having the ability to vary is different from be a variable. Just as not having the ability to vary cannot be automatically considered constant.
Immutability is different from constancy. Although I knew that some people have another understanding. I think mathematics itself does not define well what is a constant. There is something that does not vary in the algorithm and something that never varies, that I think is the true constant.
I didn’t get into the merits of it being unnecessary in the code linked in the question why it is not her focus, but if you want to know has the answer of Renan that is well in the style that I like, Desmistifying myths.
* This is going to be messy when future Java allows non-priminal value types, which is why I tell you to always conceptualize right, even when you don’t seem to need it
Half duplicate: Why File constants do not follow the convention of constants?
– user28595
@Articuno is not. It was myself who asked this question
– igventurelli
I know, but after reading this, it seemed to me the same doubt asked in another scenario.
– user28595