I try to implement an inner method in order to execute the following code in a new thread
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();
So, now I take an error which says: The final local variable result2 cannot be assigned, since it is defined in an enclosing type. I take a look at this answer: Cannot refer to a non-final variable i inside an inner class defined in a different method but it didn't work for me. What should I do to make this work?