Return type of iterator() method in java

前端 未结 6 1483
耶瑟儿~
耶瑟儿~ 2021-01-03 07:46

I am a new-comer in Java and in process of learning. I need a an answer of following question supported with valid theory. Consider the following line-

Iterat         


        
6条回答
  •  再見小時候
    2021-01-03 08:38

    The implementation is defined in AbstractList itself. Find it at its source code.

    public abstract class AbstractList extends AbstractCollection implements List {
        private class Itr implements Iterator {
           ...
        }
    
        public Iterator iterator() {
           return new Itr();
        }
    }
    

    Try

    System.out.println(new ArrayList().iterator().getClass().getName());
    

    output

    java.util.AbstractList$Itr
    

提交回复
热议问题