Joda's AbstractInstant interface extends the raw type Comparable
, instead of Comparable<AbstractInstant>
, which seems to violate Java best practices. In particular, it means that I cannot use DateTime to parameterize a class like this:
class Foo<T extends Comparable<? super T>> {
public int ct(T a, T b) {
return a.compareTo(b);
}
}
It was my understanding this kind of class was perfectly valid (it certainly works with Double, etc.). To get it to work with DateTime, though, I have litter my own code with the raw type and suppressed warnings:
@SuppressWarnings("unchecked")
class Foo<T extends Comparable> {
public int ct(T a, T b) {
return a.compareTo(b);
}
}
There is a related question that suggests a workaround (wrapping the DateTime in another class for the purposes of comparison), but I don't see why that should be necessary. My question then is:
JodaTime is designed to work on Java 1.4, and so does not use any Java 5 features, including generics.
So yes, you need to add that boilerplate warning suppression stuff in some cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With