我有兩個相同的模型類,但它們在不同的包中。 第一個是:model.my.prod.Model
和第二model.my.test.Model
2個相同的類,但來自不同的包的通用使用
我也爲這個model.my.prod.Model
內搭一件Model
類作爲參數的簡單映射:
public class Mapper{
private static Map<Model, String> models= new HashMap<>();
static {
models.put(Model.IMAGE_JPG, MediaType.IMAGE_JPEG_VALUE);
models.put(Model.IMAGE_GIF, MediaType.IMAGE_GIF_VALUE);
}
public static String createModelMap(Model model) {
if (models.containsKey(model)) {
return models.get(model);
} else {
throw new ModelException("Exeception");
}
}
}
現在我想用這個Mapper
也爲model.my.test.Model
,是否有可能沒有此Mapper
的副本並更改Model
包?
這是一個解決方案,但我認爲它與連接重複的'createModelMap'函數代碼。 – allocer