It's mainly this piece of code ^ code that i needed an explanation about because as a beginner I've never used "<>" and ":". Also I'm not sure what a EnumMap is. Preferably this one can be explained in full detail.
The <>
is part of the generics declaration, and simply associates the types you declare to the generics class you are using. For a Map
, there are two types, the Key
and the Value
, which by convention are declared as EnumMap<K,V>
So when you say:
RENDERERS_MAP= new EnumMap<State, IRenderer>(State.class);
You are saying that you wish to create an EnumMap
where the Map
key is a State
, and the Map
value is an IRenderer
. Once you declare your particular EnumMap
with your desired types, Java then takes care of casting when retrieving or setting values on the Map
.
So you can say:
IRenderer myRenderer = RENDERERS_MAP.get(myState);
without explicitly casting.