Interface ObjectInPlaceArray<E>

All Superinterfaces:
Array, ObjectArray<E>
All Known Subinterfaces:
MutableObjectInPlaceArray<E>, UpdatableObjectInPlaceArray<E>

public interface ObjectInPlaceArray<E> extends ObjectArray<E>

Special version of ObjectArray allowing to load an element without creating new Java object.

The arrays of object created via some memory models may not implement this interface. You may check, is this interface implemented, by intstanceof operator.

Author:
Daniel Alievsky
  • Method Details

    • getInPlace

      E getInPlace(long index, Object resultValue)
      Copies the content of element #index to the passed resultValue and returns resultValue. Never returns null.

      This method may work much faster than Array.getElement(long) in long loops, because allows to avoid allocating Java objects in the heap.

      Parameters:
      index - index of element to load.
      resultValue - the object where the retrieved content will be stored.
      Returns:
      a reference to resultValue.
      Throws:
      IndexOutOfBoundsException - if index out of range 0..length()-1.
      NullPointerException - if resultValue is null.
    • allocateElement

      E allocateElement()
      Creates one instance of ObjectArray.elementType() class in some state. This method, for example, may be used before a loop of calls of getInPlace(long, Object).
      Returns:
      some instance of ObjectArray.elementType() class