user3308470
user3308470

Reputation: 107

JAVA: override interface method

I have interface:

interface operations{  
    void sum();  
}   

and I want to have classes:

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

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

How to do this? I tried something like this:

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){};
}

but it doesn't work.

Upvotes: 5

Views: 23602

Answers (1)

fabian
fabian

Reputation: 82531

Don't add a type parameters to the interface and the type. Also you should specify the generic parameters of the interface you implement:

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){  
    }
}

Upvotes: 7

Related Questions