[英]Why this generic interface implementation doesn't complile?
Why this generic interface implementation doesn't complile? 为什么这种通用接口实现不合规?
//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 );
}
class Client<T> implements IClient<T> {
Oh, I found out that there is a name clash: The method compareTo(IClient) of type Client has the same erasure as compareTo(IClient) of type IClient but does not override it. 哦,我发现有一个名称冲突: Client类型的compareTo(IClient)方法与IClient类型的compareTo(IClient)具有相同的擦除,但不会覆盖它。
IClient is a raw type. IClient是原始类型。 References to generic type IClient should be parameterized
泛型IClient的引用应参数化
class Client<T> implements IClient<T>
will fix it. class Client<T> implements IClient<T>
将对其进行修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.