I am attempting to write a function that calculates the absolute maximum with an Object input. I am using an old version of the JRE (1.4), so generics are not an option. I wrote a function for returning the maximum using Comparable, but I would like to return the absolute maximum (smallest negative or largest positive). Here is my code for returning the maximum:
public Object getResult(Object objA, Object objB) {
if (objA == null) return objB;
return ((Comparable)objA).compareTo(objB) > 0 ? objA : objB;
}
The arguments will always be primitive types converted to their boxed counterparts, i.e: Float, Double, Integer, etc.
In order to find the absolute maximum, I need to get the absolute value. However, I cannot get the maximum value since these are abstract Object objects, and I cannot retrieve their values. What is the best way of doing this?