Last active
August 29, 2015 13:56
-
-
Save giuscri/8932186 to your computer and use it in GitHub Desktop.
Evitare l'uso di classi anonime in `iterator()`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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