@Beta public final class FunctionalReflection extends Object
Constructor and Description |
---|
FunctionalReflection() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
newProxy(Class<T> enclosingType,
com.google.common.base.Function<Invocation,Object> invocationFunction) |
static <T> T |
newProxy(com.google.common.reflect.TypeToken<T> enclosingType,
com.google.common.base.Function<Invocation,Object> invocationFunction)
Returns a proxy instance that implements
enclosingType by dispatching method invocations to
invocationFunction . |
public static <T> T newProxy(com.google.common.reflect.TypeToken<T> enclosingType, com.google.common.base.Function<Invocation,Object> invocationFunction)
enclosingType
by dispatching method invocations to
invocationFunction
. The class loader of enclosingType
will be used to define the proxy class.
Usage example:
httpAdapter = new Function<Invocation, Result>() { public Result apply(Invocation in) { try { HttpRequest request = parseRequest(in); HttpResponse response = invoke(request); return Result.success(parseJson(response)); } catch (Exception e) { return Result.failure(e); } } }; client = FunctionalReflection.newProxy(Client.class, httpAdapter);
invocationFunction
- returns a result or a top-level exception, or resultIllegalArgumentException
- if enclosingType
does not specify the type of a Java interfaceAbstractInvocationHandler.invoke(Object, Method, Object[])
,
Reflection.newProxy(Class, java.lang.reflect.InvocationHandler)
public static <T> T newProxy(Class<T> enclosingType, com.google.common.base.Function<Invocation,Object> invocationFunction)
Copyright © 2009-2016 The Apache Software Foundation. All Rights Reserved.