Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8181399

for-each loop should support Iterator itself

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      The for-each-loop currently only supports arrays and instances of Iterable. There's no reason, why it shouldn't also support the Iterator itself directly.

      JUSTIFICATION :
      It can be nasty and expensive to wrap an existing iterator with a dummy iterable just to use the nice and handy for each loop.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Iterator it = ...;

      for ( Object o : it )
      {
      }


      CUSTOMER SUBMITTED WORKAROUND :
      DummyIterable itbl = new DummyIterable( it );
      for ( Object o : itbl )
      {
      }

      // or:

      while ( it.hasNext() )
      {
          Object o = it.next();
      }

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: