Hi,
I'd like to write a method that can accept a type param (or whatever the method can figure out the type from) and return a value of this type so I don't have to cast the return type.
Here is a method:
public Object doIt(Object param){
if(param instanceof String){
return "string";
}else if(param instanceof Integer){
return 1;
}else{
return null;
}
}
When I call this method, and pass in it a String, even if I know the return type will be a String I have to cast the return Object. This is similar to the int param.
How shall I write this method to accept a type param, and return this type?