Java enum rozszerza obejście
Czy istnieje lepsze „obejście” niż to? Chcę uniknąć użycia PREFIX (lokalna var) podczas uzyskiwania dostępu do metod w TableMap.
public class TableMap extends TreeMap<String, String> {
public String field1, field2, field3;
public TableMap(Tables table){}
public void method(){}
public void method2(){}
public void method3(){}
...
}
obejście!
public enum Tables {
table1, table2, table3;
public final TableMap MAP=new TableMap(this);
private Tables(){}
}
potrzebne!
public enum Tables extends TableMap {
table1, table2, table3;
public Tables(){
super(table);
}
}
Przykład w całym kodzie:
// workaround!
Tables.table1.MAP.method();
Tables.table2.MAP.method();
Tables.table3.MAP.method();
...
// needed!
Tables.table1.method();
Tables.table2.method();
Tables.table3.method();
...