Skip to content

Instantly share code, notes, and snippets.

@giuscri
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuscri/8932186 to your computer and use it in GitHub Desktop.
Save giuscri/8932186 to your computer and use it in GitHub Desktop.
Evitare l'uso di classi anonime in `iterator()`
@Override
public Iterator<Giocatore> iterator() {
class IteratorOverGiocatores implements Iterator<Giocatore> {
private int currentIndex = 0;
@Override
public boolean hasNext() {
return (currentIndex < rosa.size() && !rosa.isEmpty());
}
@Override
public Giocatore next() {
return rosa.get(currentIndex++);
}
@Override
public void remove() {
rosa.remove(currentIndex -1);
}
}
// ^ Il ';' non e' necessario, direi ...
return new IteratorOverGiocatores();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment