This content has been marked as final. Show 3 replies
Not sure what code you can change and what not. Nevertheless, I will try. Why not use delegation, i.e. make ModuleRefoundTransaction have a BaseRefundTransaction field. Inheritance is not the only way to achieve code reuse.
Your line becames:
BaseRefundTransaction refundTxn = helper.getRefundTransaction().getBaseRefundTransaction();
The classes I can´t change are the ones with base on the name, BaseTransaction and BaseRefundTransaction, and also the classes that are using the helper to get a BaseRefundTransaction. I can´t either change the helper, that's part of the framework which handles all the instantiation of classes around the aplication
The error message is correct. You can't do that cast. The ModuleRefundTransaction returned by your helper does not descend from a BaseRefundTransaction so a MRT is NOT a BRT.
The problem is that in the process of extending BT to BRT you could have added some fields none of which were added to BT when you moved to MT and then to MRT. Thus if you have an MRT you can not call it a BRT because those fields would be absent.
Difficult to say what you could do about it without knowing what you are trying to preserve. You got a MRT back from your helper, you seem to want a BRT for some purpose. Since you can't cast, perhaps you can instead construct a new BRT and move the appropriate fields from you MRT to your BRT.