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

arrays should implement Iterable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 5.0, 6
    • specification
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      The new "foreach" loop works with arrays and Iterable, but these two are treated differently and it is not possible to write a function that accepts both an array and an iterable (as does the "foreach" loop).

      JUSTIFICATION :
      It is cleaner and more flexible to handle iteration over arrays in exactly the same way as iteration over collections.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect that this function accepts Iterable<Byte>, Byte[] and, with the help of autoboxing, also byte[]:

      void dumpBytes(Iterable<Byte> bytes) {
        for( Byte b : bytes) {
        }
      }

      If arrays would implement Iterable this could work.

      CUSTOMER SUBMITTED WORKAROUND :
      Currently you have to write 3 functions with different signature but identical implementation:

      void dumpBytes(Iterable<Byte> bytes) {
        for( Byte b : bytes) {
        }
      }

      void dumpBytes(Byte[] bytes) {
        for( Byte b : bytes) {
        }
      }

      void dumpBytes(byte[] bytes) {
        for( Byte b : bytes) {
        }
      }
      ###@###.### 10/11/04 05:00 GMT

            abuckley Alex Buckley
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: