Lew wrote:
I do not believe that suppressing the warning here is the answer, but
instead to declare the method with generic types in the first place.
My background is mostly in C/C++ where a warning can save you spending
three hours tracking down an errant pointer bug, so I'm in the habit of
thinking code isn't right until it compiles cleanly without suppressing
any warnings, so I'd like to use some appropriate declaration to solve
the problem if reasonably possible.
The exact form depends on what you actually are trying to do: compare
Records? Compare a type buried in a Record? Compare the exact type, or
things that extend a common supertype?
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).
case.
You could add a comment explaining why the warning should be suppressed.