對於我在Swing圖標我不同的枚舉,如:Java的泛型枚舉
public enum Icon32 {
STOP("resources/icons/x32/stop.ico"),
RUN("resources/icons/x32/run.ico");
private File path;
private Icon32(String path) {
this.path = new File(path);
}
public File getFile() {
return path;
}
或
public enum Tab {
XML("resources/icons/x32/tab/tab_1.ico"), QR("resources/icons/x32/tab/tab_2.ico"),ABOUT("resources/icons/x32/tab/tab_3.ico");
private File path;
private Tab(String path) {
this.path = new File(path);
}
public File getFile() {
return path;
}
}
我創建了一個抽象的實現:
public abstract class AbstractImageType {
private File path;
private AbstractImageType(String path) {
this.path = new File(path);
}
public File getFile() {
return path;
}
@Override
public String toString() {
return path.toString();
}
}
但是Enum不可能擴展nd:
Syntax error on token "extends", implements expected
現在我的問題,是否有可能做一個泛型類「AbstractImageType」誰實施的方法和構造函數?所以我只需要插入枚舉值?
事情是這樣的:
public enum Icon32 extends AbstractImageType {
STOP("resources/icons/x32/stop.ico"),
RUN("resources/icons/x32/run.ico");
}