Common borders with types generated before generics

I have a collection with the element type <K extends Comparable<K>> because it is ordered.

I am trying to use Joda LocalTime with this collection - for example. MyCollection<LocalTime> . Unfortunately, Yoda seems to be pre-generics; LocalTime implements raw Comparable .

I get a 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 only with a warning, since it is entirely possible to assign a raw type to a typed variable.

Why does this not work, and what can I do about it?

Here's a minimal code example:

 class Holder<K extends Comparable<K>> { } class WTF extends Holder<LocalTime> { } 
+1
java collections generics jodatime
source share
1 answer

You can create a wrapper class around LocalTime , which implements Comparable<K> and goes through all the method calls.

+1
source share

All Articles