public static <T> T getResourceByEdition(
Class<? extends ResourceFile<T>> c,
Edition edition,
Map<Edition, T> map)
{
if (map.containsKey(edition)) {
return map.get(edition);
}
T resource =
StaticResourceLoader
.getResourceLoader()
.getLocalizedResource(c, edition.getLocale());
map.put(edition, resource);
return resource;
}
我正在尝试使用泛型来获取不同类型的输入参数。因此getResourceByEdition
可用于以下两种情况:
Map<Edition, T> map
- &gt; ListMultimap<Edition, MyClass>
Map<Edition, T> map
- &gt; Map<Edition, ListMultimap<LocalDate, MyClass>>
我尝试了多种方法来适应泛型方法中的map和MultiMap。但它们都不起作用。以下是我尝试过的事情:
(Class<? extends ResourceFile<T>> c, Edition edition, Map<Edition, List<T>> map)
错误讯息:
required: Class<? extends ResourceFile<T>>, Edition,Map<Edition,<any>>
found: Class<MyClass>,Edition,ListMultimap<Edition, MyClass>
(Class<? extends ResourceFile<T>> c, Edition edition, Map<Edition, T> map)
错误讯息:
required: Class<? extends ResourceFile<T>>, Edition,Map<Edition,T>
found: Class<MyClass>,Edition,ListMultimap<Edition, MyClass>
更多想法?还是不可能?提前致谢!