为什么这个通用接口实现不能编译?
//The type Client<T> must implement the inherited abstract method IClient.compareTo(IClient)
class Client<T> implements IClient {
//The method compareTo(IClient<T>) of type Client<T> must override or implement a supertype method
//The Eclipse quick fix creates exactly the same supertype method which is defined in the interface.
@Override
public int compareTo( IClient<T> o ) {
return this.getClass().getName().compareTo( o.getClass().getName() );
}
}
interface IClient<T> extends Comparable<IClient<T>> {
@Override
int compareTo( IClient<T> o );
}发布于 2011-03-08 16:59:57
哦,我发现有一个名称冲突:类型为Client的方法compareTo( IClient )与类型为IClient的compareTo(IClient)具有相同的擦除,但没有覆盖它。
IClient是一种原始类型。对泛型类型IClient的引用应参数化
class Client<T> implements IClient<T>会解决这个问题。
发布于 2011-03-08 17:01:10
class Client<T> implements IClient<T> {https://stackoverflow.com/questions/5230282
复制相似问题