Static initialization can be complicated. You have an interdependence between A → B and B → A. The reason this is a bad idea is because the JVM starts loading statics from top to bottom in the class - if it falls into a new class that has not yet been initialized, it waits, until it initializes this class and its dependencies recursively, until everything is ready, and then continues.
Except when it is already loading a class. If A refers to B and B refers to A, it cannot start loading A a second time, or it will be an infinite loop (since A will load B again, which loads A). Thus, in this case it basically says: "The download has already begun, which you no longer need to do, continuing."
Moral of the story: depending on the order in which classes are loaded, KMUnit.INSTANCE cannot be initialized when this line is pressed:
public static final Unit KM = KMUnit.INSTANCE;
Imagine that you are a JVM and you start downloading KMUnit. He would have to load the Unit, the first time she sees it, so that, for example, create an object that is a subclass of Unit, when we get to the first creation (or, perhaps, before that - I am in a fog when statically loading the JVM ) But this, in turn, causes the static to be initialized in Unit, including this:
public static final Unit KM = KMUnit.INSTANCE; public static final Unit METERS = MeterUnit.INSTANCE;
Ok Now Unit completed the download, and we finished creating KMUnit for KMUnit.INSTANCE ... but wait - we already set KM = KMUnit.INSTANCE , which was null at that time. Therefore, it remains zero. Unfortunately.
On the other hand, if Unit loads first, then it expects KMUnit to load before initialization, so KMUnit.INSTANCE is set when we actually start the initializer.
I think. I am a little sleep deprived and I am not a specialist in the field of downloads.