问题
I've got a Collection with the element type of <K extends Comparable<K>> because it's ordered.
I'm trying to use Joda LocalTime with this collection - e.g. MyCollection<LocalTime>. Unfortunately, apparently Joda is pre-generics; LocalTime implements raw Comparable.
I'm getting the compiler error
Bound mismatch: The type LocalTime is not a valid substitute
for the bounded parameter <K extends Comparable<K>> of the type Interval<K>
I would expect this to work with just a warning, as it's quite possible to assign a raw type to a typed variable.
Why doesn't this work, and what can I do about it?
Here's a minimal code sample:
class Holder<K extends Comparable<K>> { }
class WTF extends Holder<LocalTime> { }
回答1:
You could create a wrapper class around LocalTime which implements Comparable<K> and passes through all the method calls.
来源:https://stackoverflow.com/questions/4221431/generic-bounds-with-pre-generics-raw-types