I wonder if there is a known way of finding out if a loaded
After spending quite some efforts on digging through this and reading up on the web: The
ClassLoader subsystem does not expose this information to the
Class representation. Any method information is retrieved from a native call which is already filtering away the
<clinit> method. On the JVM runtime side of things, there is only internal exposure, which can be used as a non-canonical way of finding out. For this puprpse, the
ObjectStreamClass defines a static, private method
hasStaticInitializer(Class) which is used to compute an implicit serialization UID which is rehashed by the UTF value of
Modifier.STATIC only if a class has a class initializer.
This coincidence can however be used to create a canonical way which does not use internal methods: By computing the implicit serial ID manually one can narrow this value down to two values, one value for a version of a
Class with a class initializer and one value for the same
Class without such an initializer. One can then additionally serialize the class literal and see what value the serialization engine returns. If this value represents the value that was rehashed by
<clinit>()V, one knows that the class defines such a method. Otherwise, it does not have such a value.