java - 有谁知道 内部类的方法的局部变量怎么传给外部类同时让别的类能通过类名直接调用静态方法return出去?
大家讲道理
大家讲道理 2017-04-17 17:11:58
0
4
404
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
迷茫

First of all, you are using an asynchronous request to access the network, so it is impossible to get the value synchronously when you call it. Either use OKHTTP's synchronous access to the network and return the value after the network access is completed, so that you can get the correct value, or you can control the asynchronous acquisition of the value yourself, such as getting the value after the network request is completed, that is, entering Do the operation after response.

伊谢尔伦

We do not write the inner class directly here, but let the current class inherit the interface and assign the value to the variable of the current class in the overridden method. This is my idea

PHPzhong

The getAsyn method is an asynchronous method from the name. Your getUrl will return before it receives the response, so the value in the response cannot be obtained. There are 2 solutions: getAsyn方法从名字来看是一个异步方法,你的getUrl在它收到响应之前就会返回,所以无法得到响应中的值。有2种解决办法:

  1. 看看OkHttpClientManager有没有同步方法

  2. 如果非要使用异步方法,可以在getUrl中发送异步请求之后用休眠或循环的方式等待,直到parseJson

    1. See if OkHttpClientManager has a synchronization method
  3. 🎜If you must use an asynchronous method, you can send an asynchronous request in getUrl and wait in a sleep or loop until parseJson has a value before returning. This actually turns asynchronous into synchronous in disguise. 🎜🎜 🎜
小葫芦

Personally, I think what the 1st floor said is quite right

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template