Lazy dynamic constants for Java. Implemented as dynamic constant pool entries.
Given that a significant part of the startup time of a typical Java application is taken up by class initialization, I wonder if this could be used for good effect when declaring the ubiquitous Logger
instance and such.
A more verbose alternative that works without this is:
private static Logger logger() {
class Statics {
static final Logger logger = Logger.getLogger(Parent.class);
}
return Statics.logger;
}
As the Dycon README points out, this alternative (which is a variant of the initialization-on-demand holder idiom) incurs overhead in the form of an additional class object, so it has its drawbacks. Still, you may prefer it because it does not involve bytecode trickery.