开发者

Generic bounds with pre-generics raw types

开发者 https://www.devze.com 2023-01-25 16:44 出处:网络
I\'ve got a Collection with the element type of <K extends Comparable<K>> because it\'s ordered.

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 开发者_如何学Cthe 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> { }


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

0

精彩评论

暂无评论...
验证码 换一张
取 消