/* package whatever; // don't place package name! */
import java.io.*;
import java.lang.*;
import java.util.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone {
interface Tapelibrary<T extends TapeDrive> {
List<T> getListofDrives();
void doSomethingWithDrive(T d);
}
static class SpecificTapeLibrary implements Tapelibrary<HPDrive> {
private List<HPDrive> driveList;
SpecificTapeLibrary() {
driveList.add(new HPDrive());
driveList.add(new HPDrive());
driveList.add(new HPDrive());
}
@Override
public List<HPDrive> getListofDrives() {
return driveList;
}
@Override
public void doSomethingWithDrive(HPDrive d) {
d.doSomethingHPspecific();
}
}
abstract static class TapeDrive {
void doSomething() {}
}
static class HPDrive extends TapeDrive {
void doSomethingHPspecific() {}
}
static <T extends TapeDrive> void doStuff(Tapelibrary<T> t) {
if (t == null) return;
List<T> listOfDrives = t.getListofDrives();
// the user selects a drive by using a small UI or something
T selectedDrive = listOfDrives.get(0);
t.doSomethingWithDrive(selectedDrive);
}
Tapelibrary<? extends TapeDrive> t = null;
doStuff(t);
}
}