在kotlin里面要怎么返回一个挂起函数而有不用标记?
那个动态代理是用java写的,传了个continuation进去就不需要标记挂起函数。但是如果是在kotlin中,这里会被要求标记为挂起函数或者协程中使用,而java的proxy的invoice是没有挂起函数标记的,没法用啊?应该怎么处理啊?java的写好了,但是改成kotlin不会?
public static <T> T create(Class<T> service) { return (T) Proxy.newProxyInstance(service.getClassLoader(), new Class<?>[]{service} , (o, method, args) -> { String url = ""; BaseParam requestParam = null; String requestMethod = "GET"; Class<?> returnT = method.getReturnType(); if (returnT == null || BaseResponse.class.isAssignableFrom(returnT)) { throw new RuntimeException("返回类型不是BaseResponse"); } if (method.getGenericReturnType() == Continuation.class && args != null && args.length > 0) { int len = args.length; Class clazz; for (int i = 0; i < len; i++) { clazz = args[i].getClass(); if (BaseParam.class.isAssignableFrom(clazz)) { requestParam = (BaseParam) args[i]; } } if (requestParam == null) { requestParam = new BaseParam(); } if (method.isAnnotationPresent(APIGet.class)) { url = method.getAnnotation(APIGet.class).value(); } else if (method.isAnnotationPresent(APIPost.class)) { url = method.getAnnotation(APIPost.class).value(); requestMethod = "POST"; } Continuation<?> continuation = (Continuation<?>) args[args.length - 1]; return OkHttpProxy.INSTANCE.await(NetWorkManager.Companion.getInstance().call(url, requestParam, requestMethod), returnT, continuation); } return null; }); }