package javavk public class Main public static void main String args N

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package javavk;
public class Main {
public static void main(String[] args) {
Num<Float> num1 = new Num<>(5.0f);
Num<Byte> num2 = new Num<>((byte) 4);
System.out.println(num1.compareTo(num2));
System.out.println(num2.compareTo(num1));
}
}
class Num<T extends Number> implements Comparable<Num<?>> {
private final T val;
public Num(T val) {
this.val = val;
}
public T getVal() {
return val;
}
@Override
public int compareTo(Num<?> o) {
return (int) (this.val.doubleValue() - o.val.doubleValue());
}
}