我有一个被称为参数的方法,如下面的代码...我需要在我的代码中的 Oncomplete 方法之外使用参数“arry”..有没有办法可以实现这一点?
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
String arry = graphObject.getProperty("data").toString();
}
}
最佳答案
创建一个扩展(实现)Request.Callback 的类并将其传递给该方法。
该类可以存储String arry。
class RequestCallback extends Request.Callback {
private String arry;
public String getArry() {
return arry;
}
public void inCompleted(Response response) {
this.arry = graphObject.getProperty("data").toString();
}
}
然后:
RequestCallback callback = new RequestCallback();
Request request = new Request(session, "/fql", params, HttpMethod.GET, callback);
...
// after the request is completed
callback.getArry(); // and use it.
关于java - 从方法中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15448817/