### Question:
SingleAccessMethodCompiler { public static <T> T compileSingleAccessMethod(String suggestedClassName, Class<T> interfaceType, MethodHandle methodHandle) { ClassDefinition classDefinition = new ClassDefinition( a(PUBLIC, FINAL, SYNTHETIC), makeClassName(suggestedClassName), type(Object.class), type(interfaceType)); classDefinition.declareDefaultConstructor(a(PUBLIC)); Method method = getSingleAbstractMethod(interfaceType); Class<?>[] parameterTypes = method.getParameterTypes(); MethodHandle adaptedMethodHandle = methodHandle.asType(methodType(method.getReturnType(), parameterTypes)); List<io.airlift.bytecode.Parameter> parameters = new ArrayList<>(); for (int i = 0; i < parameterTypes.length; i++) { parameters.add(arg("arg" + i, parameterTypes[i])); } MethodDefinition methodDefinition = classDefinition.declareMethod( a(PUBLIC), method.getName(), type(method.getReturnType()), parameters); CallSiteBinder callSiteBinder = new CallSiteBinder(); BytecodeExpression invocation = invokeDynamic( BOOTSTRAP_METHOD, ImmutableList.of(callSiteBinder.bind(adaptedMethodHandle).getBindingId()), method.getName(), method.getReturnType(), parameters); if (method.getReturnType() != void.class) { invocation = invocation.ret(); } methodDefinition.getBody().append(invocation); ClassLoader classLoader = SingleAccessMethodCompiler.class.getClassLoader(); Class<? extends T> newClass = defineClass(classDefinition, interfaceType, callSiteBinder.getBindings(), classLoader); try { T instance = newClass .getDeclaredConstructor() .newInstance(); return instance; } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } } private  SingleAccessMethodCompiler(); static T compileSingleAccessMethod(String suggestedClassName, Class<T> interfaceType, MethodHandle methodHandle);  }### Answer:
@Test public void testBasic() throws ReflectiveOperationException { LongUnaryOperator addOne = compileSingleAccessMethod( "AddOne", LongUnaryOperator.class, lookup().findStatic(TestSingleAccessMethodCompiler.class, "increment", MethodType.methodType(long.class, long.class))); assertEquals(addOne.applyAsLong(1), 2L); }
@Test public void testGeneric() throws ReflectiveOperationException { @SuppressWarnings("unchecked") LongFunction<String> print = (LongFunction<String>) compileSingleAccessMethod( "Print", LongFunction.class, lookup().findStatic(TestSingleAccessMethodCompiler.class, "incrementAndPrint", MethodType.methodType(String.class, long.class))); assertEquals(print.apply(1), "2"); }