When I define static or constant members, for example:
public static final Font BIG_FONT = new Font("", Font.BOLD, 18);
I noticed that they only load when I first use them, which either results in freezes during the runtime or forces me to somehow preload them by forcefully ‘using’ the constant at the program launch.
Aren’t static members of such type supposed to be loaded at program launch rather than wait to be loaded on first use? How can I make sure they are preloaded?
Thanks in advance.
In Java, statics are initialized when the class is first used, not when the static member itself is first used. You can force “pre-loading” by using any other member of that class, not necessarily the static field itself.