In my Spring boot project, I have several different methods that are each called with different parameters but they have a common list of elements, actions, which can be one of two types of objects (ActionCommon or ActionInstance) but both implement the same interface Action. However, despite using upper bound generics, I am getting no suitable method found error and I have no idea why.
This is a spring boot project consisting of several modules, this is a new module providing new functionality using existing data model (which I cannot edit). Much of the functionality is the same, the only difference between functions is the amount of arguments.
I've tried using directly the interface instead of generics, but my list returns as a list of specific objects using the interface and I cannot change that.
PriceService.java
public interface PriceService {
List<Price> parseActionsToPrices(List<? extends Action> actions, Client client, Offer offer)
List<Price> parseActionsToPrices(List<? extends Action> actions, Client client, Contract contract)
....more functions
}
OfferService.java
public class OfferServiceImpl implements OfferService
@Autowired
PriceService priceService
@Override
public List<Price> getPrices(Client client, Offer offer) {
List<ActionCommon> actions = offer.getActions();
return priceService.parseActionsToPrices(actions, client, offer)
}
}
ContractService.java
public class ContractServiceImpl implements ContractService
@Autowired
PriceService priceService
@Override
public List<Price> getPrices(Client client, Contract contract) {
List<ActionInstance> actions = contract.getActions();
return priceService.parseActionsToPrices(actions, client, contract)
}
}
Usage in question is
Get a list of either ActionCommon or ActionInstance from a function.
Call interface method with said list and the appropriate arguments .
Expect result of function back
Instead, I get a (for example) no suitable method found for parseActionToPrices(List<ActionCommon>, Client, Offer)
error.
Same result for all the methods.