Source:
<code>private void registerMethod(@Nonnull final MethodHandles.Lookup caller, @Nonnull final AbstractServer server, @Nonnull final Method method) { final ServerHandler annotation = method.getAnnotation(ServerHandler.class); if (!method.getParameterTypes()[0].isAssignableFrom(annotation.type().messageType .getRawType())) { throw new UnrecoverableCorfuError("Incorrect message type, expected " + annotation.type().messageType.getRawType() + " but provided " + method.getParameterTypes()[0]); } if (handlerMap.containsKey(annotation.type())) { throw new UnrecoverableCorfuError("HandlerMethod for " + annotation.type() + " already registered!"); } try { HandlerMethod<CorfuMsg> h; if (Modifier.isStatic(method.getModifiers())) { MethodHandle mh = caller.unreflect(method); MethodType mt = mh.type().changeParameterType(0, CorfuMsg.class); <START> h = (HandlerMethod<CorfuMsg>) LambdaMetafactory.metafactory(caller, <END> "handle", MethodType.methodType(HandlerMethod.class), mt, mh, mh.type()) .getTarget().invokeExact(); } else { MethodType mt = MethodType.methodType(method.getReturnType(), method.getParameterTypes()); MethodHandle mh = caller.findVirtual(server.getClass(), method.getName(), mt); MethodType mtGeneric = mh.type().changeParameterType(1, CorfuMsg.class); h = (HandlerMethod<CorfuMsg>) LambdaMetafactory.metafactory(caller, "handle", MethodType.methodType(HandlerMethod.class, server.getClass()), mtGeneric.dropParameterTypes(0, 1), mh, mh.type().dropParameterTypes(0, 1)).getTarget() .bindTo(server).invoke(); } final HandlerMethod<CorfuMsg> handler = generateConditionalHandler(server, annotation.type(), h); handlerMap.put(annotation.type(), handler); } catch (Throwable e) { log.error("Exception during message handler registration", e); throw new UnrecoverableCorfuError(e); } }</code><technical_language>discussion, some point get rid of meta introspections do pay cost in fast paths</technical_language>

Target:
private void registerMethod(@Nonnull final MethodHandles.Lookup caller, @Nonnull final AbstractServer server, @Nonnull final Method method) { final ServerHandler annotation = method.getAnnotation(ServerHandler.class); if (!method.getParameterTypes()[0].isAssignableFrom(annotation.type().messageType .getRawType())) { throw new UnrecoverableCorfuError("Incorrect message type, expected " + annotation.type().messageType.getRawType() + " but provided " + method.getParameterTypes()[0]); } if (handlerMap.containsKey(annotation.type())) { throw new UnrecoverableCorfuError("HandlerMethod for " + annotation.type() + " already registered!"); } try { HandlerMethod<CorfuMsg> h; if (Modifier.isStatic(method.getModifiers())) { MethodHandle mh = caller.unreflect(method); MethodType mt = mh.type().changeParameterType(0, CorfuMsg.class); h = (HandlerMethod<CorfuMsg>) LambdaMetafactory.metafactory(caller, "handle", MethodType.methodType(HandlerMethod.class), mt, mh, mh.type()) .getTarget().invokeExact(); } else { MethodType mt = MethodType.methodType(method.getReturnType(), method.getParameterTypes()); MethodHandle mh = caller.findVirtual(server.getClass(), method.getName(), mt); MethodType mtGeneric = mh.type().changeParameterType(1, CorfuMsg.class); h = (HandlerMethod<CorfuMsg>) LambdaMetafactory.metafactory(caller, "handle", MethodType.methodType(HandlerMethod.class, server.getClass()), mtGeneric.dropParameterTypes(0, 1), mh, mh.type().dropParameterTypes(0, 1)).getTarget() .bindTo(server).invoke(); } final HandlerMethod<CorfuMsg> handler = generateConditionalHandler(annotation.type(), h); handlerMap.put(annotation.type(), handler); } catch (Throwable e) { log.error("Exception during message handler registration", e); throw new UnrecoverableCorfuError(e); } }