While doing some Java homework I answered a question by writing an instance method, in the method I made use of some static final variables that belonged to the class the method was in. I wrote the static variable names without prefixing them with the class’ name, for example:
for(int i=0; i < MY_STATIC_VARIABLE; i++)
instead of
for(int i=0; i < MyClass.MY_STATIC_VARIABLE; i++)
This compliled and worked correctly. It was only later that I noticed I had forgotten to prefix the class’ name. Does it matter whether I include the class name or not? Does a static final variable act like a global variable within the context of its class?
To your teacher, and future people reviewing code at companies you end up working for, maybe. But maybe not – If I were reviewing your code, I’d suggest leaving out the class name in this case.
To the compiler, no, it doesn’t matter.
Sure does