以下代码产生堆栈溢出错误,有人可以告诉我为什么吗?(如果我在方法中引用“super”而不是“this”,我知道如何修复错误,add
但我不确定为什么会这样。)
package subclassingVector;
import java.util.Vector;
public class MyVectorSubclass extends Vector<MyModelClass> {
public MyVectorSubclass(){
MyModelClass m = new MyModelClass();
m.setId(2);
this.add(m);
if(this.contains(m)){
System.out.println("contains is true");
}
}
public boolean add(MyModelClass o){
this.add(o);
return true;
}
public boolean contains(Object o){
for(subclassingVector.MyModelClass mmc: this){
if(mmc.equals((MyModelClass) o)){
return true;
}
}
return false;
}
public static void main(String[] args) {
String s = new String("SSEE");
MyVectorSubclass m = new MyVectorSubclass();
}
public class MyModelClass {
private Integer id = null;
public MyModelClass() {
// TODO Auto-generated constructor stub
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
}