关于泛型类的,想知道哪里错了,为什么错
接口部分
public interface Compute {
abstract void add();
abstract void substract();
abstract void mulitiply();
abstract void divide();
}
————————————————————————
泛型类部分(主要错误就在这里面)
public class Computer<N> implements Compute{
public <N> X;
public <N> Y;
public Computer(){
}
public Computer(<N> x,<N> y){
X=x;
Y=y;
}@Override
public void add() {
// TODO Auto-generated method stub
System.out.print(X+"+"+Y+"="+X+Y);
}
@Override
public void substract() {
// TODO Auto-generated method stub
System.out.println(+X+"-"+Y+"="+(X-Y));
}
@Override
public void mulitiply() {
// TODO Auto-generated method stub
System.out.println(X+"/"+Y+"="+X/Y);
}
@Override
public void divide() {
// TODO Auto-generated method stub
System.out.println(+X+"*"+Y+"="+X*Y);
}
public <N> getX() {
return X;
}
public void setX(<N> x) {
X = x;
}
public <N> getY(){
return Y;
}
public void setY(<N> y){
Y=y;
}
}
————————
实现部分
public class TextComputer {
public static void main(String[] args) {
Computer<Number> c=new Computer<Number>();
c.setX(7);
c.setY(8);
c.add();
c.divide();
c.mulitiply();
c.substract();
}
}