I have a class like this
class Dummy{
public getData(Info info){
List<SomeType> list = info.getDataAsPerInfo();
List<SomeType> result=new List<>();
for(SomeType someType: list){
// extracting data from someType, lets say this data is
// resType (it also of SomeType)
result.add(resType);
}
}
public static void main(String args[]){
Info1 info = new Info1(); // Info1 extends Info
// adding paramters to info
new Dummy().getData(info);
}
}
Now the problem is that I have several Info classes like Info1, Info2 ...
and there getData method might return different types of list. I can't figure how to achieve this without rewriting the code for each and every Info class( this would involve replacing SomeType with the return type of that class' getdataAsPerInfo function).
Is there a way such that I can somehow use SomeType according to the Info type that is passed to the getData function? What would be the best approach in this case? Thanks !!