Instantiating a SuperClass Map from a SubClass
I am trying to design a abstract class that will instantiate a Map through a subclass, using an enum type that implements a interface. Contract will be that subclass must instantiate and set variables in it's own constructor.
Here is an example:
Here is the variable from the superclass (T extends Enum & PreferencesIDs)
protected Map<T, String> stringList;
and the abstract method:
protected abstract void setPreferences();
While I define the subclass I either can't compile the code or get a bunch of warnings.
Attempt (Either through EnumMaps or HashMaps, using an pIDs enum that implements PreferenceIDs):
stringList = new EnumMap<pIDs, String>(pIDs);
When I do this, I get this error:
DataPreferenceManager.java:28: warning: [unchecked] unchecked assignment to variable stringList as member of raw type abstractPreferences.AbstractPreferences
stringList = new EnumMap<pIDs, String>(pIDs.class);
DataPreferenceManager.java:30: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Map
Now, is there anyway to do this a more correct way? Any obvious answers? I don't mind reading myself, I just haven't found any direct answers so far.
Re: Instantiating a SuperClass Map from a SubClass
Can you post a better defined example that reproduces the error you are encountering, or better yet what you want to achieve? From what I understand it seems you wish to constrain a preferences Map to a few specific values and use Generics to have a compile time rather than runtime error?