I want to have a class with multiple static variables that will only be initialized on demand.
public class Messages {
public static final String message1 = init1();
public static final String message2 = init2();
}
So when somewhere in the code I reference Messages.message1
I want only init1()
to be called. If later I access Messages.message2
then only at that time should init2()
be called.
I know it is possible to do this with the Initialization-on-demand holder idiom, but this is cumbersome if you have lots of fields.
Is there another way?