对于我在 Swing 中的图标,我有不同的枚举,例如:
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 无法扩展:
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");
}