I have a String, which can be either of type Double, or Integer, or of another type. First I need to create a Double or Integer object, and then send it to the overloaded method. Here is my code so far;
public void doStuff1(object obj, String dataType){
if ("Double".equalsIgnoreCase(dataType)) {
doStuff2(Double.valueOf(obj.toString()));
} else if ("Integer".equalsIgnoreCase(dataType)) {
doStuff2(Integer.valueOf(obj.toString()));
}
}
public void doStuff2(double d1){
}
public void doStuff2(int d1){
}
I would like to do this without if / else, with something like this:
Class<?> theClass = Class.forName(dataType);
The problem is that "theClass" still cannot be added to either double or int. I would appreciate any ideas. Thank.
Find the connected stream; Java overload and multiple submission
source
share