2 回答

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊
你說的很簡單Object
。它是最具體的常見超類:
private static Map<String, Object> properties;
其他解決方案是制作Inventory
和Shipping
實現(xiàn)一些通用接口,例如Named
并將其用作HashMap
.

TA貢獻(xiàn)1856條經(jīng)驗 獲得超5個贊
一種方法是制作Shipping和Inventory實現(xiàn)相同的接口(如VariableObject在您的 cas 中)
public class Event {
private static String type;
private static Map<String, VariableObject> properties;
public static void main(String[] args) {
Inventory inventory = new Inventory("inventoryName", 13);
properties.put("Inventory", inventory);
Shipping shipping = new Shipping("shippingName", true);
properties.put("Shipping", shipping);
}
}
public interface VariableObject{
//you can define common methods here if you want
}
public class Inventory implements VariableObject{
private static String name;
private static int someNumber;
public Inventory(String name, int someNumber) {
this.name = name;
this.someNumber = someNumber;
}
}
public class Shipping implements VariableObject{
private static String name;
private static boolean someBoolean;
public Shipping(String name, boolean someBoolean) {
this.name = name;
this.someBoolean = someBoolean;
}
}
添加回答
舉報