I want to create an anonymous inner class that extends another class.
What I want to do is actually something like the following:
for(final e:list){
Callable<V> l = new MyCallable(e.v) extends Callable<V>(){
private e;//updated by constructor
@Override
public V call() throws Exception {
if(e != null) return e;
else{
//do something heavy
}
}
};
FutureTask<V> f = new FutureTask<V>(l);
futureLoadingtask.run();
}
}
Is this possible?
You cannot give a name to your anonymous class, that’s why it’s called “anonymous”. The only option I see is to reference a
finalvariable from the outer scope of yourCallableAnother option is to scope a local class (not anonymous class) like this:
If you need more than that, create a regular
MyCallableclass…