Last active
August 29, 2015 14:17
-
-
Save cls/3cfaba9c6c185e976a48 to your computer and use it in GitHub Desktop.
Adaptor for covariant iterators in Java
This file contains 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
import java.util.Iterator; | |
public class CovariantIterator<T extends U, U> implements Iterator<U> | |
{ | |
private Iterator<T> iter; | |
public CovariantIterator(Iterator<T> it) | |
{ | |
this.iter = it; | |
} | |
public CovariantIterator(Iterable<T> it) | |
{ | |
this(it.iterator()); | |
} | |
@Override | |
public boolean hasNext() | |
{ | |
return this.iter.hasNext(); | |
} | |
@Override | |
public U next() | |
{ | |
return (U) this.iter.next(); | |
} | |
@Override | |
public void remove() | |
{ | |
this.iter.remove(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment