Search code examples
javaconcurrencyjava.util.concurrent

AtomicStampedReference.get() method: why parameter is array?


Some time ago I started to investigate java.util.concurrent package. And my question is about AtomicStampedReference class. The class has method

public V get(int[] stampHolder) {
    ...
}

which gets reference and stamp atomically (please, correct me if I'm wrong).

Is there some special reasons why parameter for the method is array? Documentation says nothing about it.


Solution

  • Maybe (probably) it is just a hack to simulate out parameters, since in this case two values should be returned: V and an int value.

    Another possibility would be to return a tuple Tuple<V,Integer>, but Java has no Tuple class, and it would maybe be less efficient to create an instance of a Tuple object and additionally boxing the int, which may be important in the context of concurrency.