本文整理了Java中retrofit2.Retrofit.callAdapter
方法的一些代码示例,展示了Retrofit.callAdapter
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Retrofit.callAdapter
方法的具体详情如下:
包路径:retrofit2.Retrofit
类名称:Retrofit
方法名:callAdapter
[英]Returns the CallAdapter for returnType from the available #callAdapterFactories().
[中]从可用的#CallAdapterFactorys()返回returnType的CallAdapter。
代码示例来源:origin: square/retrofit
private static <ResponseT, ReturnT> CallAdapter<ResponseT, ReturnT> createCallAdapter(
Retrofit retrofit, Method method) {
Type returnType = method.getGenericReturnType();
Annotation[] annotations = method.getAnnotations();
try {
//noinspection unchecked
return (CallAdapter<ResponseT, ReturnT>) retrofit.callAdapter(returnType, annotations);
} catch (RuntimeException e) { // Wide exception range because factories are user code.
throw methodError(method, e, "Unable to create call adapter for %s", returnType);
}
}
代码示例来源:origin: square/retrofit
@Override
public T invoke(Object proxy, Method method, Object[] args) throws Throwable {
Type returnType = method.getGenericReturnType();
Annotation[] methodAnnotations = method.getAnnotations();
CallAdapter<R, T> callAdapter =
(CallAdapter<R, T>) retrofit.callAdapter(returnType, methodAnnotations);
return callAdapter.adapt(behaviorCall);
}
});
代码示例来源:origin: com.squareup.retrofit2/retrofit
private static <ResponseT, ReturnT> CallAdapter<ResponseT, ReturnT> createCallAdapter(
Retrofit retrofit, Method method) {
Type returnType = method.getGenericReturnType();
Annotation[] annotations = method.getAnnotations();
try {
//noinspection unchecked
return (CallAdapter<ResponseT, ReturnT>) retrofit.callAdapter(returnType, annotations);
} catch (RuntimeException e) { // Wide exception range because factories are user code.
throw methodError(method, e, "Unable to create call adapter for %s", returnType);
}
}
代码示例来源:origin: VictorAlbertos/Mockery
<T> T adapt(Method method, NetworkBehavior networkBehavior, Call<?> call) {
try {
Class<?> behaviorCallClass = Class.forName("retrofit2.mock.BehaviorCall");
Constructor<?> constructor = behaviorCallClass.getDeclaredConstructor(NetworkBehavior.class,
ExecutorService.class, Call.class);
constructor.setAccessible(true);
Call<?> behaviorCall = (Call<?>) constructor.newInstance(networkBehavior,
Executors.newCachedThreadPool(),
call);
return (T) retrofit
.callAdapter(method.getGenericReturnType(), method.getAnnotations())
.adapt(behaviorCall);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!