I don't really know why the behaviour changes between Java 6 and Java 7 (have you verified that with other compilers? javac
vs. Eclipse compiler vs. whatever IDEA uses?).
But I can tell you why compareTo(Delayed)
does not implement compareTo(Object)
when you extend ScheduledFuture
:
By using ScheduledFuture
, you're using a raw type, which means that all occurances of generics are pretty much ignored in your class. That means that you're now implementing Comparable
(and no longer Comparable<Delayed>
, which in turn means that you need to implement compareTo(Object)
(the erasure of Comparable<Delayed>.compareTo()
), but you implement compareTo(Delayed)
.
Remember: Raw types are meant only for backwards compatibility. Avoid them in new code at all costs, they do nasty things!
When you change your extends
clause to ScheduledFuture<Object>
you "opt-in" to the generics system and the compiler finally realizes (i.e. "is allowed to realize") that your compareTo(Delayed)
is in fact the proper implementation of the Comparable<Delayed>
interface.