2012-04-08 5 views
3

ArrayListを拡張して、カスタムArrayListを作成しています。カスタムArrayListは、通常のArrayListメソッドを使ってそれを反復処理しながら変更できます。このためにIteratorも作成しています。私のhasNext()、次の()メソッドの間にInnerクラスからクラスを囲む方法を参照するには?

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 
} 
} 

は、私はリストが(それは他のどの時点で変更することができます)に変更されていないことを確認する必要があります。したがって、私はsynchronized()ブロックで囲むタイプを参照する必要があります。

+0

[Access Outer Class this instance](http://stackoverflow.com/questions/1721608/access-outer-class-this-instance)と[内部クラスオブジェクトから外部クラスオブジェクトを保持する](http://stackoverflow.com/questions/1816458/getting-hold-of-the-outer-class-object-from-the-inner-class-object) –

答えて

5

EnclosingType.this。あなたの場合はSynchronizedList.thisになります。

関連する問題