第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Iterator<Course> it = coursesToSelect.iterator();

這個(gè)語句中的it是什么呢?是iterator的對(duì)象嗎?iterator是一個(gè)接口,為什么能夠聲明it呢?

正在回答

3 回答

對(duì)于集合來說,接口中的方法都是內(nèi)部實(shí)現(xiàn)的,你可以查看AbstractList<E>中有相關(guān)聲明

?public Iterator<E> iterator() {

? ? ? ? return new Itr();

? ? }

?private class Itr implements Iterator<E> {

? ? ? ? /**

? ? ? ? ?* Index of element to be returned by subsequent call to next.

? ? ? ? ?*/

? ? ? ? int cursor = 0;


? ? ? ? /**

? ? ? ? ?* Index of element returned by most recent call to next or

? ? ? ? ?* previous. ?Reset to -1 if this element is deleted by a call

? ? ? ? ?* to remove.

? ? ? ? ?*/

? ? ? ? int lastRet = -1;


? ? ? ? /**

? ? ? ? ?* The modCount value that the iterator believes that the backing

? ? ? ? ?* List should have. ?If this expectation is violated, the iterator

? ? ? ? ?* has detected concurrent modification.

? ? ? ? ?*/

? ? ? ? int expectedModCount = modCount;


? ? ? ? public boolean hasNext() {

? ? ? ? ? ? return cursor != size();

? ? ? ? }


? ? ? ? public E next() {

? ? ? ? ? ? checkForComodification();

? ? ? ? ? ? try {

? ? ? ? ? ? ? ? int i = cursor;

? ? ? ? ? ? ? ? E next = get(i);

? ? ? ? ? ? ? ? lastRet = i;

? ? ? ? ? ? ? ? cursor = i + 1;

? ? ? ? ? ? ? ? return next;

? ? ? ? ? ? } catch (IndexOutOfBoundsException e) {

? ? ? ? ? ? ? ? checkForComodification();

? ? ? ? ? ? ? ? throw new NoSuchElementException();

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? public void remove() {

? ? ? ? ? ? if (lastRet < 0)

? ? ? ? ? ? ? ? throw new IllegalStateException();

? ? ? ? ? ? checkForComodification();


? ? ? ? ? ? try {

? ? ? ? ? ? ? ? AbstractList.this.remove(lastRet);

? ? ? ? ? ? ? ? if (lastRet < cursor)

? ? ? ? ? ? ? ? ? ? cursor--;

? ? ? ? ? ? ? ? lastRet = -1;

? ? ? ? ? ? ? ? expectedModCount = modCount;

? ? ? ? ? ? } catch (IndexOutOfBoundsException e) {

? ? ? ? ? ? ? ? throw new ConcurrentModificationException();

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? final void checkForComodification() {

? ? ? ? ? ? if (modCount != expectedModCount)

? ? ? ? ? ? ? ? throw new ConcurrentModificationException();

? ? ? ? }

? ? }

簡單來說,就是集合內(nèi)部實(shí)現(xiàn)Iterator接口的方法,私有的

0 回復(fù) 有任何疑惑可以回復(fù)我~

coursesToSelect.iterator();?

?

0 回復(fù) 有任何疑惑可以回復(fù)我~

是的。一樣可以對(duì)象的

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

六代目 提問者

能具體解釋一下嗎
2015-06-15 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

Iterator<Course> it = coursesToSelect.iterator();

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)