Let me start with a disclaimer on possible duplicate... I did try to pore over a few questions on this topic but they did not represent my challenge on what I want to achieve. So kindly bear with me and help with a solution.
Here is my situation: I have an interface (in command pattern) as below for which I need an implementation for.
public interface IIntelligentAction<E> {
/**
* Set dynamic variable for this action.
*/
public void setDynamicOperand(Callable<?> getter);
/*
* Set validating operand for this action.
*/
public void setValidatingOperand(Callable<?> getter);
/*
* The implementation must check if the operands (dynamic and validating) are
* compatible with each other for this action.
*/
public boolean areOperandsCompatible();
/*
* Execute this action.
* <p> The implementation must check for both operands being assigned and are
* compatible with each other, before allowing the action to execute.
*/
public void execute();
}
The design of the interface is intentional and I understand the rationale (for ex., Date
and Calendar
are semantically compatible but not type compatible.
Now my concern is in the areOperandsCompatible()
method. As can be seen, the method accepts a parameterised Callable
, so by reflection I will always see Callable
but not the type it will return. How do I get access to the parameterised type of the generic instance I get from the setter methods?