我正在做一个练习,我需要实现一个类,我很难理解解释。
这是解释/练习:
* Adds all of the elements in the specified set, for which it is
* possible, to this set.
* post: all elements, for which it is possible, in the
* specified set are added to this set.
* @return true if this set changed as a result of the call
这就是答案
public boolean addAll(SimpleSet<? extends E> s) {
Iterator<? extends E> it = s.iterator();
boolean changed = false;
while (it.hasNext()) {
changed = add(it.next());
}
return changed;
}
这就是我自己尝试做的事情,但是我很难把我的头绕在我应该做的事情上。
public boolean addAll(SimpleSet<? extends E> s){
Iterator<? extends E> itr = s.iterator();
while(itr.hasNext()){
add(itr.next());
}
return true;
}
感谢任何可能的帮助,
鲍比。