Relates :
|
See https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066991.html and https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066994.html /** * To the given method handle, prepend an action, if necessary, to trigger * initialization of the given class the first time the method handle is called. * If it would be illegal to call ensureInitialized on the given class from this lookup, * immediately report an error. Otherwise, if the class is already fully initialized * return the method handle unchanged. Otherwise, return a new method handle * (of the same type) which incorporates the necessary initialization action, * as if by a call to ensureInitialized. */ MethodHandle ensureInitialized(Class target, MethodHandle mh) { checkAccess(target); if (isFullyInitialized(target)) return mh; // we need to tack a “before action” onto mh to trigger inits: MethodHandle before = MH_ensureInit.bindTo(target); return collectArguments(mh, 0, before); }