I've got following method:
public Iterator<Item> iterator() {
return new ListIterator();
}
and it's used in following code:
Deque<Integer> deque = new Deque<Integer>();
// ...
Iterator<Integer> iter1 = deque.iterator();
Iterator iter2 = deque.iterator();
The question is - why does java compiler accept both lines (iter1
& iter2
)? Especially the iter2
is strange for me. When I create my former object (deque) I need to specify the type on both sides.
Anyway, if I put
Deque deque2 = new Deque();
then compiler is fine with this too. Confusing...