Retroifit原理
生活随笔
收集整理的這篇文章主要介紹了
Retroifit原理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
反射+動態代理
@SuppressWarnings("unchecked") // Single-interface proxy creation guarded by parameter safety.public <T> T create(final Class<T> service) {Utils.validateServiceInterface(service);if (validateEagerly) {eagerlyValidateMethods(service);}return (T) Proxy.newProxyInstance(service.getClassLoader(), new Class<?>[] { service },new InvocationHandler() {private final Platform platform = Platform.get();private final Object[] emptyArgs = new Object[0];@Override public @Nullable Object invoke(Object proxy, Method method,@Nullable Object[] args) throws Throwable {// If the method is a method from Object then defer to normal invocation.if (method.getDeclaringClass() == Object.class) {return method.invoke(this, args);}if (platform.isDefaultMethod(method)) {return platform.invokeDefaultMethod(method, service, proxy, args);}return loadServiceMethod(method).invoke(args != null ? args : emptyArgs);}});}?
總結
以上是生活随笔為你收集整理的Retroifit原理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python递归求5!_Python |
- 下一篇: 【转】匈牙利命名法(Hungarian