public class MyList<Item> implements Iterable<Item> {
Node<Item> first;
int n = 0;
private static class Node<Item>
{
private Item item;
private Node<Item> next;
}
public Iterator<Item> iterator() {
return new ListIterator<Item>();
}
private class ListIterator<Item> implements Iterator<Item> // parameter Item is hiding the type Item
{
private Node<Item> current = first; // This does not compile
public boolean hasNext() {
return (current != null);
}
public Item next() {
Item item = current.item;
current = current.next;
return current.item;
}
}
...
}
The error I get is
"Type Mismatch : can't convert from MyList.Node to MyList.Node".
Not sure if this is related to the warning
"paramter Item is hiding the type item"
If I get a warning for private class ListIterator<Item> implements Iterator<Item>
, why did I not get a warning for public class MyList<Item> implements Iterable<Item>
?