When asking When are enums first created?
The answer is: When the enum class is first loaded.
Then when asking: When are enums first loaded?
the answer seems to be: When they are.
The JVM helps us instantiate enumeration types when they are loaded
When looking deep into the concept of "loading" we come across "Loading, Linking, and Initializing", and so the clear implication seems to be that loading happens "when it is first needed".
The reason why I am asking this is because I came across a post in which someone wrongfully thought that enums were loaded on to Metaspace before the first line of a program was executed.
And I never even noticed it, but I realized that I had the same thought process, and some of the answers in that post seem to imply that whenever an enum or private static constant are present as a field inside a class, then that class is bound to a synchronization performance hit for each and every instance concurrently created of said class, if and only if multiple instances are being created for the first time (in a concurrent manner), so that each object gets the same instance of the enum and/or static constant.
So the question: If the compiler has all the code information before executing the program, why does it chooses to load constants and enums whenever they are first needed?
Is this done out of uncertainty that maybe the code will not execute, saving memory space if it doesn't?