Take the following example class:
public class GlobalExample{
static int width;
static int height;
static int size;
}
The class members can be accessed / initialized from a separate class using:
GlobalExample.width = 1
However, if I wanted to make the variables final (which as I understand it makes things more efficient when a program is accessing variables a lot) they can no longer be initialized externally, but they also can’t seem to be initialized within the class outside of the constructor. However since GlobalExample is never initialized itself, the constructor wouldn’t run.
My question is whether there is a way to initialize final variables within the class.
Alternately, am I just barking up the wrong tree efficiency-wise? Would it be more efficient to make an instance of a VariablePackage class and just pass it into a million function calls?
Thanks
Are you unable to initialize them when you declare them?
If you have to modify them dynamically, perhaps
finalis not suitable here.