JAVA:覆盖接口方法

用户名

我有界面:

interface operations{  
    void sum();  
}   

我想上课:

class matrix implements operations {  
    @override   
    void sum(matrix m) {  
    } 
}

class vector3D implements operations {  
    @override  
    void sum(vecor3D v) {  
    }
}

这该怎么做?我尝试过这样的事情:

interface operations < T > {  
    <T> void sum(T t);  
}

class matrix implements operations<matrix>{
    @Override
    void sum(matrix m){};
    }
}

class vector3D implements operations<vector3D>{
    @Override
    void sum(vector3D v){};
}

但这是行不通的。

法比安

不要在接口类型中添加类型参数另外,您还应该指定要实现的接口的通用参数:

interface operations<T> {  
    void sum(T t);  
}



class matrix implements operations<matrix> {  
    @Override   
    public void sum(matrix m){  
    } 
}



class vector3D implements operations<vecor3D> {  
    @Override  
    public void sum(vecor3D v){  
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章