A quick call for help on generics.
Joda-Time has the following non-generic interface, with an example dummy implementation:
public interface ReadableInstant extends Comparable {
...
int compareTo(Object readableInstant);
...
}
public class Dummy implements ReadableInstant {
...
public int compareTo(Object readableInstant) { ... }
...
}
I've been trying to generify this and maintain backwards binary and source compatibility without success. The following naive implementation works fine for new code:
public interface ReadableInstant extends Comparable<ReadableInstant> {
...
int compareTo(ReadableInstant readableInstant);
...
}
This doesn't work fine when the old code is combined (unaltered and without recompilation) with the new library.
Firstly, the old code is not source compatible.
Dummy does not implement the altered method in the newly generified interface, thus the
old code doesn't compile without change.
Furthermore, it is not binary compatible.
Imagine a second class Foo that implements the generified version of ReadableInstant.
Now consider a class which loads Dummy (unaltered and without recompilation)
by reflection as a ReadableInstant and calls
compareTo to compare. This will throw an AbstractMethodError.
This is because Foo expects there to be a method of the generified form, taking ReadableInstant.
So, its basically a mess. I can't come up with a way to preserve backwards compatibility while adding generics. But I thought the whole point was to allow migration compatibility!
So, I thought that perhaps I'm missing something stupid. If so, please let me know! All the code is in svn (1.6 branch and TRUNK) for anyone wanting to play with real code.