I wonder if it is possible to write a method that will handle casting of undefined types like:
Precondition:
Map<String, Object> map = new HashMap<>();
List<String> l = List.of("value");
map.put("key", l);
Method call:
List<String> strings = convert("key", List.class, String.class);
convert method itself:
public <V, C extends Collection<V>> C<V> getCollection(String key, Class<C> collType, Class<V> objectType) {
return (C<V>) map.get(key);
}
But statement C< V > doesn't compile and gives me an error: Type 'C' doesn't have type parameters.
Any ideas?