开发者

Why this generic interface implementation doesn't complile?

开发者 https://www.devze.com 2023-02-15 16:55 出处:网络
Why this generic interface implementation doesn\'t complile? //The type Client<T> must implement the inherited abstract method IClient.compareTo(IClient)

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

精彩评论

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

关注公众号