I'm reading the source code of ArrayList and this class has an inner class with the name SubList
. I'm looking in a method of the inner class (SubList
) and see the following methods:
public E set(int index, E e) {
rangeCheck(index);
checkForComodification();
E oldValue = ArrayList.this.elementData(offset + index);
ArrayList.this.elementData[offset + index] = e;
return oldValue;
}
What I see that line 3 & 4 uses this
keyword in order to call/use ArrayList
(outer class) method/attribute.
I want to understand is it must to use OuterClass.this
or elementData()
will be enough? I run an example long ago (more than a year) and I was able to call an outer class method from an inner class without using this
keyword.