回调的封装
- package com.nan.cnshop.http;
- import com.google.gson.internal.$Gson$Types;
- import com.squareup.okhttp.Request;
- import com.squareup.okhttp.Response;
- import java.lang.reflect.ParameterizedType;
- import java.lang.reflect.Type;/**
- * 根本的回调
- */public abstract class BaseCallback<T> { /**
- * type用于便利JSON的解析
- */
- public Type mType; /**
- * 把type转换查对应的类,这里不消看明白也行。
- *
- * @param subclass
- * @return
- */
- static Type getSuperclassTypeParameter(Class<?> subclass) {
- Type superclass = subclass.getGenericSuperclass();
- if (superclass instanceof Class) {
- throw new RuntimeException("Missing type parameter.");
- }
- ParameterizedType parameterized = (ParameterizedType) superclass;
- return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
- } /**
- * 构造的时刻获得type的class
- */
- public BaseCallback() {
- mType = getSuperclassTypeParameter(getClass());
- } /**
- * 请求之前调用
- */
- public abstract void onRequestBefore();
- /**
- * 请求掉败调用(收集问题)
- *
- * @param request
- * @param e
- */
推荐阅读
吉林打造"互联网+公安"服务平台 让群众感受"指尖"上的便利
吉林省公安机关一年多来,积极整合警务资本,力推简政放权,全力打造“互联网+公安”办事平台,“把能上彀的都搬上互联网”,让广大年夜人平易近群众足不出户感触感染到&l>>>详细阅读
本文标题:利器OkHttp的使用以及简单封装
地址:http://www.17bianji.com/lsqh/35424.html
1/2 1