public final class MyClass {
private Connection connection;
public Example(Connection c){
this.connection = c;
}
public interface ConnectionWorker{
void doSomething(Connection conn);
}
public void work(ConnectionWorker worker){
worker.doSomething(connection);
}
}
(A) Example can be subclassed in order to specialize the implementation of MyClass.work(ConnectionWorker)
(B) Specialization is achieved through implementation of a ConnectionWorker
(C) The call to worker.doSomething must be synchronized on worker
(D) worker.doSomething must launch a worker thread passing conn and then wait with Thread join
A是錯的,因為這是final class,CD在代碼中沒有提到。看上去應該選B。通過實現ConnectionWorker接口並且傳給work方法實現對doSomething的Specialization。