Re: Initializing a Map in an Interface?
In article <lZKdnVdCN8aZ3QLWnZ2dnUVZ8vVi4p2d@eclipse.net.uk>,
Ian Smith <email@example.com> wrote:
Isn't this sort of thing that Enums and EnumMaps are meant for? Just
asking . . .
Consider a situation where the design starts out using Enum but later
needs to load definitions from a configuration file. That can't be done
with Enum, EnumMap, or code that works with them. The original poster
mentioned having large sets of definitions of Colors so I think a design
using Enum would run into future problems.
If Enums were to be used for declaration of data that may later become
dynamic, I'd transfer them to a Map that had keys and values that aren't
Enums. Unfortunately the code isn't so clean now. Two classes must be
defined and they're both public.
public interface FooColor
Black (new Color(0, 0, 0)),
Obscure_Gray (new Color(51, 51, 51)),
Dark_Gray (new Color(102, 102, 102)),
Light_Gray (new Color(153, 153, 153)),
Pale_Gray (new Color(204, 204, 204)),
White (new Color(255, 255, 255));
public final Color color;
NamedColorSet (Color c)
public static final Map<String, Color> EIGHT_BIT_COLORS =
Collections.unmodifiableMap(new HashMap<String, Color>()
for (NamedColorSet n : NamedColorSet.values())
put (n.name(), n.color);
I won't see Google Groups replies because I must filter them as spam