this
always refers to the current object. So, inside MyIterator
, this
refers to the MyIterator
instance, not the list.
You need to use LinkedUserList.this.head
, or simply head
, to access the head
member of the outer class. Note that inner classes can access private members of their outer class, so head
doesn't need to be protected
. It can be private
.