Here you can find the source of emptyIterator()
@SuppressWarnings("unchecked") public static final <T> ListIterator<T> emptyIterator()
//package com.java2s; /*//w ww. jav a 2 s . c o m * Copyright 2008-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at: * * http://aws.amazon.com/apache2.0/ * * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific * language governing permissions and limitations under the License. */ import java.util.ListIterator; import java.util.NoSuchElementException; public class Main { public static final ListIterator<?> EMPTY_ITERATOR = new ListIterator() { public boolean hasNext() { return false; } public boolean hasPrevious() { return false; } public Object next() { throw new NoSuchElementException(); } public Object previous() { throw new NoSuchElementException(); } public void remove() { throw new IllegalStateException(); } public int nextIndex() { return 0; } public int previousIndex() { return -1; } public void add(Object o) { throw new UnsupportedOperationException(); } public void set(Object o) { throw new UnsupportedOperationException(); } }; @SuppressWarnings("unchecked") public static final <T> ListIterator<T> emptyIterator() { return (ListIterator<T>) EMPTY_ITERATOR; } }