I am trying to compare two subclasses of Number inside a class with generics. In the code below, I am trying to compare Number objects inside a Datum instance.
How to ensure that both parameters passed to the Datum constructor are of the same class, so I can compare what, as I know, with comparable types. Float and Float, or Long and Long?
Float f1 = new Float(1.5); Float f2 = new Float(2.5); new Datum<Number>(f1, f2); class Datum<T extends Number> { T x; T y; Datum(T xNum, T yNum) { x = xNum; y = yNum; if (x > y) {}
user668660
source share