package javavk public class NumExample public static void main String

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package javavk;
public class NumExample {
public static void main(String[] args) {
System.out.println(compare(7, 24.342));
System.out.println(compare((byte)-10, -15f));
System.out.println(compare(0.1, 0.2));
System.out.println(compare(0.2, 0.1));
}
private static <T extends Number> int compare(T num1, T num2) {
return (int) Math.signum(num1.doubleValue() - num2.doubleValue());
}
}