"반복자를 유형으로 확인할 수 없습니다."라는 오류가 발생합니다. 저장소 클래스를 가져 와서 Java의 Collections 클래스를 구현하는 데 필요한 코드를 추가하려고합니다. Iterator를 가져올 수 없다고 생각합니다. 내 자신을 만들어야한다고 생각합니다.컬렉션 클래스에 대해 자체 반복자를 만드는 데 문제가 있습니다.
public class storage {
private Object[] data = new Object[256];
// Don't allow access to anything not yet stored
private int nextEmptySlot = 0;
private int i=0;
public Object begin(){
return data[0];
}
public Object end(){
return data[nextEmptySlot];
}
//class Iterator() {
// public Storage data;
//}
public Iterator iterator() {
// returns a class that iterates over the data array
return new Iterator() {
public Object remove(){
for(int j=i+1 ; j<=nextEmptySlot-1 ; j++) {
this.data[j-1] = this.data[j];
}
return (this.data.data[i]);
}
public int hasNext(){
if(this.data.data[i+1] != null) return 1;
else return 0;
}
public Object next(){
i++;
if (hasNext()==1){
return this.data.data[i];
}
else if (hasNext()==0){
throw UnsupportedOperationException();
}
return this;
}
};
}
}
일반적으로 클래스 이름은 대문자로 시작됩니다. '저장소' –