No, it doesn't contravene the spec. Initialization *does* occur before
invocation, but not before the attempt to invoke. As the spec explains.
The spec explains no such thing -- fortunately, because it doesn't make
sense. You cannot separate "the attempt to invoke" from "invocation".
The two go hand in hand like the attempt to catch a ball and the
successful catch. How can they not? Until the first byte of the main
method's bytecode is executing the attempt may or may not be successful;
success is defined by the main method's bytecode being entered and
starting to execute! How *else* could one sensibly define the attempt to
invoke said bytecode? But then initialization *must* precede the attempt
to not violate the spec, because otherwise it occurs after at least the
first byte of the main method begins executing. And by then it's too
late. The main method will see stuff uninitialized that the spec
requires it never see uninitialized, and there goes your claim to have a
conformant implementation. And until that moment, the "attempt to
invoke" is not guaranteed to succeed and is therefore still an attempt
and not an invocation by your own peculiar worldview in which you regard
the two as somehow separate.
The same thing happens in Java 5 (and should have happened in 1.2
through 1.4), if you refer to the 'class' literal of a class before any
action that triggers intialization, the class will be loaded but not
initialized.
How does loading it right away in such cases accomplish anything useful?
The class literal might as well evaluate to a memory-cheap stub-object
that is transparently replaced with the real class object when, and only
when, something is done with it that goes beyond bandying it about,
printing it, using its monitor, getting its hashcode, or comparing it
for equality. And the things that would then trigger actual loading also
are the ones that trigger initialization. Such a scheme would be *much*
more in what you previously called the "spirit of lazy initialization".
These are facts which completely undercut "JSnarker"'s claim.
In a pig's eye.
Only by your twisted and, shall we say "unique", interpretation of it.
See?
There is a point at which a class has been loaded, verified and
prepared, but not initialized.
Nothing in that says that that circumstance should be anything but very
brief, and it's clear that it must exist *at least* very briefly as
loading obviously must precede initialization.
As for the process happening upon an attempt to invoke, here's language
from 12.1.1:
"The initial attempt to execute the method main of class Test discovers
that the class Test is not loaded ..."
Where's your temporal sequence now, O Snarky One? As I have stated and
you have obstinately rejected repeatedly, the loading (if not yet done)
and initialization occurs upon the attempt to invoke, i.e., the attempt
happens first, conceptually.
What it says is that an attempt is made and fails because the class is
not both loaded and initialized. It is loaded, if necessary, and
initialized, and then a fresh attempt is automatically made. THAT
attempt may then succeed, or fail for other reasons, such as the method
doesn't exist.
Read the JLS and understand.
Already did that. Still waiting for you to practice what you preach, thoguh.