I have this static factory method:
public static CacheEvent getCacheEvent(Category category) {
switch (category) {
case Category1:
return new Category1Event();
default:
throw new IllegalArgumentException("category!");
}
}
Where Category1Event is defined as;
class Category1Event implements CacheEvent<Integer> ...
My client code for above static factory method looks like:
CacheEvent c1 = getCacheEvent(cat1);
EDIT:
The above code works fine. However I prefer that I don't use raw type CacheEvent
and rather use the parameterized type. An obvious disadvantage of using the raw type above is, I will have to cast in following cases:
Integer v = c1.getValue(); // ERROR: Incompatible types, Required String, Found Object.
I can do an unchecked assignment as follows, but this gives a warning. I am trying to avoid if it is possible.
// Warning: Unchecked Assignment of CacheEvent to CacheEvent<Integer>.
CacheEvent<Integer> c1 = getCacheEvent(cat1);