java - Enforcing generics on a map -
java - Enforcing generics on a map -
i'm trying write simple caching class. cache map class list. want declare map in way enforce list item class same class of key. following:
class cache { private static map<class<? extends codedentity>, list<? extends codedentity>> map; }
is not plenty because won't enforce (in decleration) want. map needs static , there no point in declaring class t because don't want limited single type. there syntactic way accomplish this?
you map private, why don't enforce need in accessor , mutator methods?
public <t extends codedentity> void addtocache(class<t> key, list<t> values) { map.put(key, values); } public <t extends codedentit> list<t> getfromcache(class<t> key) { homecoming (list<t>) map.get(key); }
java generics
Comments
Post a Comment