A private class that calls a method from its outer class

Ok, so I have a class for "Extended Data Structure" (in this case, it's kind of a tree) So I included the Iterator as a private class. Thus, the iterator needs to implement a delete function to remove the last retuirned element.

now my ADT is already implementing a delete function, in which case there is very little (thinking about it, I don't think anything) to benefit from implementing a different delete function for an iterator.

since i need to call delete from my ADT

a sketch of my struture:

public class ADT {
...
   private class ADT_Iterator impliments  java.util.Itorator{
      ...
      public void remove(){
          //where I want to call the ADT remove function from
      }
...

    public void remove( Object paramFoo )
    {
     ...
    }

    ...     

}

      

So just calling remove (FooInstance) won't work (right?) And this.remove (FooInstance) is the same thing.

what can I name? (and changing the name of the ADT delete function is not an option, as AD T must match the Interace which I want to mark to change)

I could get both of them to call the removeHelper function, I think ...

+2


a source to share


2 answers


ADT.this.remove(object)

      



(Although simply calling remove (object) will work in this case, since it has a different signature than the remove () method in the iterator.)

+4


a source


To get a reference to an outer class that the inner class is "attached" use ClassName.this, in your case:



   private class ADT_Iterator impliments  java.util.Itorator{
      ...
      public void remove(){
          ADT.this.remove(obj)
      }

      

+3


a source







All Articles