Hello
I'm trying to access a custom Java generic stored in a map as below.
Unfortunately I get a type mis-match error.
Now, I can cast it to the type I want because but this seems messy to me.
Is there a clean way of doing the assignment?
Thanks
public interface BusinessObject {
}
public class SalesItemA implements BusinessObject {
}
public interface BusinessRuleSuite<T extends BusinessObject> {
public void fire(T shell);
}
public abstract class BusinessRuleSuiteCommon<T extends BusinessObject>
implements BusinessRuleSuite<T> {
public synchronized void fire(T bo) {
// do something with bo;
}
}
public class SalesBusinessRuleSuite extends
BusinessRuleSuiteCommon<SalesItemA> {
}
public class SalesProcessor {
private final Map<Class<? extends BusinessObject>, BusinessRuleSuite<? extends BusinessObject>> businessRules;
public SalesProcessor(Map<Class<? extends BusinessObject>, BusinessRuleSuite<? extends BusinessObject>> businessRules) {
this.businessRules = businessRules;
}
public void processItem(SalesItemA sia) {
/// This assignment doesn't work??? Why?
BusinessRuleSuite<SalesItemA> p = this.businessRules.get(sia.getClass());
p.fire(sia);
}
}
}