【发布时间】:2011-08-25 04:00:36
【问题描述】:
我有一个带有类似签名的超类
public abstract class Foo<C extends Comparable<? super C>>{..}
所以 C 类应该是 Comparable 对象。
我想使用 org.joda.time.Instant(1.6 版)作为子类中的类型参数
public class SubFoo<Instant>
不幸的是,我收到了这个错误:
Bound mismatch: The type Instant is not a valid substitute for the bounded parameter <C extends Comparable<? super C>> of the type BigtablePoller<T,C>
Instant 类扩展了实现 Comparable(无类型参数)的 AbstractInstant
有没有办法解决这个问题?
我能够使其工作的唯一方法是将 Foo 更改为:
@SuppressWarnings("rawtypes")
public abstract class Foo<C extends Comparable> {}
我想避免警告,而 Josh Bloch 说不要在新代码中使用原始类型(有效的 java 条款 23)。
【问题讨论】: