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

SegmentAllocator::allocateArray call can be ambiguous

XMLWordPrintable

      A call to SegmentAllocator::allocateArray, such as:

          allocator.allocateArray(JAVA_LONG, 10);

      Is somewhat ambiguous. It is not clear whether this should create an uninitialized long array with 10 elements, or a long array with a single element initialized to '10'.

      i.e. either of the following overloads of allocateArray is applicable:

          default MemorySegment allocateArray(MemoryLayout elementLayout, long count)
          default MemorySegment allocateArray(ValueLayout.OfLong elementLayout, long... elements)

      Overload resolution picks the former.

      We could rename one of these methods to disambiguate a use case such as this.

            mcimadamore Maurizio Cimadamore
            jvernee Jorn Vernee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: