我尝试实现一个内部方法,以便在新线程中执行以下代码
MyPojo result = null;
final MyPojo result2 = result;
FutureTask<MyPojo> runnableTask = new FutureTask<MyPojo>(
new Runnable() {
BindJSON<MyPojo> binding;
// Make the URL at which the product list is found
String sourceURLString =
"http://www.....ca/files/{CAT_ID}.json";
@Override
public void run() {
sourceURLString = sourceURLString.replace("{CAT_ID}", catId);
binding = new BindJSON<MyPojo>();
result2 = binding.downloadData(sourceURLString, MyPojo.class);
}
},
result2);
runnableTask.run();
所以,现在我收到一条错误消息:无法分配最终的局部变量 result2,因为它是在封闭类型中定义的。我看一下这个答案:Cannot reference a non-final variable i inside an internal class defined in a different method但它对我不起作用。我应该怎么做才能完成这项工作?