使用枚舉雖然很方便歸類常亮 可是有時數量太大的話看起來不美觀,使用也不方便,一聯想出來一大堆。bash
可使用接口來作歸類枚舉類ide
好比:ui
public interface CarTree {
String getBrandModel();
enum BmwEnum implements CarTree{
X1("x1", "寶馬"),
X2("x2", "寶馬"),
X6("x6", "寶馬");
String model;
String brand;
BmwEnum(String model, String brand) {
this.model = model;
this.brand = brand;
}
@Override
public String getBrandModel() {
return this.brand + "-" + this.model;
}
}
enum BuickEnum implements CarTree {
Regal("君威", "別克");
String model;
String brand;
BuickEnum(String model, String brand) {
this.model = model;
this.brand = brand;
}
@Override
public String getBrandModel() {
return this.brand + "-" + this.model;
}
}
}
複製代碼