Java – why include class names when referencing static variables?
When doing some Java jobs, I answered a question by writing an instance method. In the method, I used some static final variables belonging to the class of the method I wrote static variable names without prefixing them with class names, for example:
for(int i=0; i < MY_STATIC_VARIABLE; i++)
replace
for(int i=0; i < MyClass.MY_STATIC_VARIABLE; i++)
This allows the to get involved and work properly It was not until later that I noticed that I forgot to prefix the name of the class Is it important that I include the class name? Does the static final variable act as a global variable in the context of its class?
Solution
For your teachers and future staff, you may view the code in the company where you end up working But maybe not - if I'm reviewing your code, I recommend omitting the class name in this case
For compilers, no, it doesn't matter
Certainly.