I have 2 different maps of different types, both of which are subclasses of BaseClass.
I has hoping to be able to use the same logic for 'saving' an item to the map for both cases, using Generics.
assume getId is a method of BaseClass.
I need to force
- the itemto be a subclass ofBaseClass
- the mapvalue to be the same type as theitem
How can I do this? here is a failed attempt which kind of describes what I need to do:
private <T><?extends BaseClass> void save(T item, Map<Long, T> map)
{
    if (item.getId() == null)
    {
        long max = -1;
        for (Long key : map.keySet())
            max = Math.max(max, key);
        item.setId(max + 1);
    }
    map.put(item.getId(), item);
}
 
    