For example, there needs to be a written a generic program for addition. It needs to be intelligent in a way that it determines the type of arguments passed to it and then output the answer in the same type. For more elaboration:
If I want to write only one method to add two numbers ( of any type like int, float, double etc), what should I do that the method itself determines the type of number passed and returns the calculated sum in the same type?
Is there any way to sort this out? Any help would be highly appreciated!
Code view: For example arguments passed are 5 & 6 i.e. integers.
addition(5,6);
Now, what I want is a function add that somehow determines the type (i.e. integer in this case) & returns the result. Like:
public (determined return type) add((determined returned type) space variable, (determined returned type) space variable){
return result;
}