如何解决迭代器类方法在main中无法访问
我尝试使用 iterator() 方法访问该 ArrayIterator 类。但我不能在 main 中使用 setValue 方法。它看不到那个方法。我怎样才能让它在主要内容中可见?有人可以帮我吗?(我在 ArrayIterator 中添加了其他方法。)
public class ArrayIterator implements Iterator<E> {
int current = 1;
public boolean hasNext() {
return current < n;
}
public E next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
System.out.println(getSize());
System.out.println(getHeap()[current]);
return heap[current++];
}
public E setValue(E item){
if (!hasNext()) {
throw new NoSuchElementException();
}
E result = heap[n];
heap[n] = item;
return result;
}
}
@Override
public Iterator<E> iterator() {
return new ArrayIterator();
}
也是我的主课;
Heap<Integer> j = new Heap<>();
Iterator<Integer> iter = j.iterator();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。