阅读背景:

在一个方法调用之前保证另一个方法已经执行

来源:互联网 
    private class LinkedListIterator implements Iterator<AnyType>{
        private Node<AnyType> current = beginMarker.next;
        private int expectedModCount  = modCount;
        private boolean okToMove = false; 
    	@Override
		public boolean hasNext() {
			return current!=endMarker;
		} 
		@Override
		public AnyType next() {
			if(modCount != expectedModCount){
				throw new ConcurrentModificationException();
			}
			if(!hasNext()){
				throw new NoSuchElementException();
			}
			
			AnyType nextItem = current.data;
			current = current.next;
			okToMove = true;
			return nextItem;
		} 
		@Override
		public void remove() {
			if(modCount != expectedModCount){
				throw new ConcurrentModificationException();
			}
			if(!okToMove){ //防止连续调用remove方法
				throw new IllegalStateException();
			}
			MyLinkedList.this.remove(current.pre);
			expectedModCount--;
		} 
    }     private class LinkedListIterator implements



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: