我认为答案关键取决于
Foo子类管理的数据类型。如果结果是同质的,只需相应地扩展
SwingWorker和实例化具体的子类:
class Whatever {}abstract class AbstractFoo extends SwingWorker<List<Whatever>, Whatever> {}class Foo1 extends AbstractFoo { @Override protected List<Whatever> doInBackground() throws Exception { ... }}如果每个都管理不同的类型,则使父类通用,并使用所需的类型实例化每个具体的子类:
class Whatever {}class Whichever {}abstract class GenericAbstractFoo<T, V> extends SwingWorker<T, V> {}class Foo2 extends GenericAbstractFoo<List<Whatever>, Whatever> { @Override protected List<Whatever> doInBackground() throws Exception { ... }}class Foo3 extends GenericAbstractFoo<List<Whichever>, Whichever> { @Override protected List<Whichever> doInBackground() throws Exception { ... }}


