开发者

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().compa开发者_JAVA百科reTo( 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.

IClient is a raw type. References to generic type IClient should be parameterized

class Client<T> implements IClient<T> will fix it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜