We write a library that use generics, i am not sure how to create an instance of generic type. Shortly how to write create method?
public class Lib<V extends Base> {
private HashMap<Integer, V> map = new HashMap<Integer, V>();
public V get(int key) {
return map.get(key);
}
public void add(int key, V value) {
map.put(key, value);
}
public void create(int key) {
// V v = new V(); // ?? How to implement this line
// add(key++, v);
}
}