void (Document document) { Class<?> klass = myHighlightingDataClass.getValue(); if (klass != null) { try { MethodHandles.Lookup lookup = MethodHandles.publicLookup(); MethodHandle ctor = lookup.findConstructor(klass, MethodType.methodType(void.class, Document.class, boolean.class, boolean.class)); Object instance = ctor.invoke(document, true, true); lookup.findVirtual(klass, "init", MethodType.methodType(void.class)).invoke(instance); } catch (Throwable t) { LOG.error(t); } } }