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

Extended for loops

XMLWordPrintable

    • tiger
    • generic
    • generic

      Name: krT82822 Date: 10/12/99


      I believe that having foreach functionality in the Java Language
      would be an excellent addition. This is easy to explain and
      understand, so I will be brief.

      Here is some sample code of mine:

      Iterator paneIter= contentLists.keySet().iterator();

      while(paneIter.hasNext()) {

         String paneName= (String) paneIter.next();
         //... loop body, maybe just one line
      }

      I would like for 'each' functionality so that this can reduce to:

      for(String paneName, contentLists.keySet()) {
         //... loop body (no braces necessary if just one line)
      }

      Basically, what the compiler does is understand that the second
      parameter to the for() construct is a Collection. Knowing
      what a Collection is, it gets the iterator, and can produce in
      a very straight forward way, the bytecode for the loop for the
      code I first wrote.

      10/12/99 eval1127@eng -- see also # 4183241
      (Review ID: 96439)
      ======================================================================

            gbrachasunw Gilad Bracha (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: