Of course it is possible. First of all, the double function can accept int values, so you can use that for both if you want. However, if you still want to achieve your goal, the best way is to use generics. Another way is to make your method accept a parent of both classes for example Object and then cast appropriately as shown below:
public class Add {
enum ParamType {
INT,
DOUBLE
}
public static Object add(Object i, Object j, ParamType paramType) {
if (paramType.equals(ParamType.INT)) {
return (int) i + (int) j;
} else {
return (double) i + (double) j;
}
}
public static void main(String[] args) {
System.out.println(add(3.4, 5.2, ParamType.DOUBLE));
System.out.println(add(3, 5, ParamType.INT));
}
}