Java generic function for performing calculations on integer, on double?

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2011-01-14T20:40:07Z Indexed on 2011/01/14 20:53 UTC
Read the original article Hit count: 152

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics