Lew<lewbloch@gmail.com> wrote:
Referencing the 'class' literal does not incur class initialization.
from JLS 12.4.1:
A class [...] T is initialized immediately before first [...]
T is a class and an instance of T is created.
T is a class and a static method declared by T is invoked.
A static field declared by T is assigned.
A static field declared by T is used [ ... and not constant ... ]
T is a top-level class, and an assert statement (??14.10) lexically
nested within T is executed.
Does using a class-literal<T.class> in "synchronized(T.class) {...}" count
in for implicitly using the monitor-field of the Class<T>-instance, or is
it strictly undefined (or defined somewhere else)?
Btw., I don't understand the point about assert. If the assert is
lexically nested in T and gets executed, then I'd have naively thought,
that one of the first two points would necessarily have happened,
anyway, before the assert could be reached. What am I missing here?
Suppose S is a static class defined in T. I interpreted that as meaning
that executing an assert in S would trigger initialization of T.
Or suppose S is non-static, but the assert is in its static code.