How to refer to Enclosing class from Inner class?

I am extending ArrayList to create a custom ArrayList that can be modified using normal ArrayList methods while iterating over it. For this I am also creating an Iterator.

public class SynchronizedList<E> extends ArrayList<E>
{
    // Fields here

    //Constructors and methods here

public class SynchronizedListIterator<E> implements Iterator<E>
{
    public int index;
    private E current;

    public boolean hasNext()
    {
        synchronized (/* reference to enclosing List object */) {
                    //code goes here
        }
        return false;
    }

    //more methods here
}
}

During my hasNext() and next() methods, I need to make sure the list is not modified (it can be modified at any other time). Hence I need to refer to my enclosing type in my synchronized() block.

Answers


EnclosingType.this. So in your case, it would be SynchronizedList.this.


Need Your Help

counting 1 word, 2 word and 3 word phrases occurrences in a webpage in C#/.NET

c# word counting

I'm going to write a program that takes a URL and counts the occurrences of EVERY single 1-word, 2-word, and 3-word phrases in the webpage (and possibly x-word phrases).

jQuery serialize() throws empty string in Rails

jquery ruby-on-rails

jQuery serialize() throws empty string from a form, here is the source of the form

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.