【发布时间】:2016-03-12 17:03:40
【问题描述】:
您好,这是我第一次提出问题,所以可能不是最好的。 所以我正在开发一个使用继承和实现的项目。我的问题是当我运行比较或等于方法时,java 给了我一个堆栈溢出错误,我到处寻找解决这个问题,但无法这样做。这可能只是一个简单的我不知道要问什么。
//this is from the class that inherits
@Override
public boolean equals(Object o){
if(this.equals(o)){
return true;
}
return false;
}
//This is what its inheriting from
public boolean equals(Object o){
boolean findings;
findings = this.getStrength().equals(((Weapon)o).getStrength());
if(strength == ((Weapon)o).strength){
return true;
}
return false;
}
//this code is an instance of another
@Override
public int compareTo(Force o) {
return this.compareTo(o);
}
您能提供的任何建议将不胜感激。谢谢。
public class Pizza extends Store {
public Pizza(int strong){
super.changeStrength(strong);
}
@Override
public boolean equals(Object o){
if(o!=null){
if(super.getStrength()==((Pizza)o).getStrength()){
return true;
}
}
return false;
}
}
这里是披萨类的代码
【问题讨论】:
标签: java compare project equals