Java generic function for performing calculations on integer, on double?
- by Daniel
Is this possible? Surely if you passed in a double, any sort of function implementation code which casts an object to an Integer would not be able to work unless the cast 'Integer' was specifically used? I have a function like:
public static void increment(Object o){
Integer one = (Integer)o;
system.out.println(one++);
}
I cant see how this could be made generic for a double? I tried
public static <E> void increment(E obj){
E one = (E)o;
system.out.println(one++);
}
but it didn't like it?