2012-04-08 1 views
3

ArrayList를 확장하여 일반 ArrayList 메서드를 사용하여 수정할 수있는 사용자 지정 ArrayList를 만듭니다. 이를 위해 Iterator를 만들고 있습니다. 내 hasNext()와 다음() 메소드 동안내부 클래스에서 클래스를 둘러싸는 방법을 참조 하시겠습니까?

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이됩니다.