class Cache // holds objects of various subclasses of Base {
private Map<String, Base> objTable = new Hashtable<String, Base>(INITIAL_ENTRI ES);
public <T extends Base> List<T> getObjectsByType(String typeName) { List<T> objs = new ArrayList<T>(); synchronized (objTable) { Iterator<Base> itr = objTable.values().iterator(); Base obj; while (itr.hasNext()) { obj = itr.next(); if (obj.isObjectOf(typeName)) { // isObjectOf() is available already objs.add((T)obj); // UNCHECKED CAST: Base to T } } } return objs; }