Ivan Voras wrote:
public class MyIter implements Iterator<Hashtable<String,Object>>,
Iterable {
public Iterator iterator() {
Just to reinforce what Roedy and Daniel said, you normally implement
Iterable<T>, not Iterator<T> and you return a parameterized Iterator<T>
public class MyIter implements Iterable<Hashtable<String,Object>>,
{
// ...
public Iterator<Hashtable<String,Object>> iterator()
{ // ...
}
}
Of course you class really isn't a "MyIter" any more, it's "MyIterable".
You could return a "MyIter" though.. oh I just noticed that your class
really is both an Iterator and a Iterable... that's not normal. Consider
a private inner class instead.
public class MyIter implements Iterable<Hashtable<String,Object>>,
{
// ...
public Iterator<Hashtable<String,Object>> iterator()
{ // ...
return new Itor();
}
private class Itor implements Iterator<Hashtable<String,Object>>
{
public boolean hasNext() {...}
public void remove() {...}
public Hashtable<String,Object> next() {...}
}
}
This encapsulates (hides) your implementation a little better.
The choice of 'Hashtable' as a type parameter is rather strange. Why not