To explain problem consider I have 6 classes
- ClassOne
- ClassTwo
- ClassThree
- ClassFour
- ClassFive
- ClassImpl
I have method startOperation(List<String> classNameList), in this method I am iterating classNameList and for every class name I am using reflection to get object of the that class now I want to call method doOperation() which is an overloaded method.
private void doOperation(ClassOne objClassOne) {
//Do somethig
}
private void doOperation(ClassTwo objClassTwo) {
//Do somethig
}
.. And so on up to
private void doOperation(ClassFive objClassFive) {
//Do somethig
}
my startOperation method looks like:
public void startOperation(List<string> classNameList) {
for (String string : classNameList) {
Class actualClass = Class.forName(className);
Object classObj = actualClass.newInstance();
doOperation(classObj); // here I am getting problem
}
}
please tell how to call overloaded method from within the loop.
Note: classNameList dynamically contain names of different classes I don't want to hard code anything as some classes may get added to project or some may get removed I just want to add or delete respective doOperation method when this happen.