Why do Joda coins extend the original Comparable type?

The Joda AbstractInstant interface extends the original Comparable type instead of Comparable<AbstractInstant> , which seems to violate the best Java examples . In particular, this means that I cannot use DateTime to parameterize such a class:

 class Foo<T extends Comparable<? super T>> { public int ct(T a, T b) { return a.compareTo(b); } } 

It was my understanding that this class was absolutely right (it certainly works with Double, etc.). To make it work with DateTime, I put my own code with a raw type and suppressed the 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 offers a workaround (wrapping DateTime in another class for comparison purposes), but I don't understand why this should be necessary. Then my question is:

  • Does anyone know why Joda extends raw type or
  • Is this a mistake I have to tell the library developers?
+6
java jodatime
source share
1 answer

JodaTime is designed to run on Java 1.4 and therefore does not use any Java 5 features, including generics.

So yes, in some cases you need to add this warning header.

+2
source share

All Articles