You could rely on the fact that the primitive wrappers all implement the Comparable interface...
public static Comparable min(Comparable c1, Comparable c2){
return c1.compareTo(c2) < 0 ? c1 :...
Type: Posts; User: copeg
You could rely on the fact that the primitive wrappers all implement the Comparable interface...
public static Comparable min(Comparable c1, Comparable c2){
return c1.compareTo(c2) < 0 ? c1 :...
Just use the Math class
int i1 = 5;
int i2 = 10;
float f1 = 1.0;
float f2 = 5;
double d1 = 1;
double d2 = 10;
System.out.println(Math.min(i1,i2));
System.out.println(Math.min(f1,f2));
Why use generics then? Do you want to compare primitives or objects? To compare intergers, just pass primitives:
int min(int val1, int val2){
return val1 < val2 ? val1 : val2;
}
Or just use...