Documentation of 'javolution37.javolution.realtime.StackReference' Java class
StackReference
javolution37.javolution.realtime

Class StackReference<T>

  • All Implemented Interfaces:
    Reference<T>, Realtime


    public final class StackReference<T>
    extends RealtimeObject
    implements Reference<T>

    This class encapsulates a reference allocated on the current stack when executing in PoolContext. The reachability level of a stack reference is the scope of the PoolContext in which it has been created.

    Stack references are automatically cleared based upon their reachability level like any java.lang.ref.Reference. In other words, stack references are automatically cleared when exiting the PoolContext where they have been factory produced.

    Stack references are typically used by functions having more than one return value to avoid creating new objects on the heap. For example:

         // Returns both the position and its status.
         public Coordinates getPosition(Reference<Status> status) {
             ...
         }
         ...
         StackReference<Status> status = StackReference.newInstance(); // On the stack.
         Coordinates position = getPosition(status);
         if (status.get() == ACCURATE) ...
    See also ConcurrentContext for examples of StackReference usage.

    • Method Detail

      • newInstance

        public static <T> StackReference<T> newInstance()
        Returns a new stack reference instance allocated on the current stack when executing in PoolContext.
        Returns:
        a local reference object.
      • toText

        public Text toText()
        Returns the text representation of the current value of this reference.
        Specified by:
        toText in interface Realtime
        Overrides:
        toText in class RealtimeObject
        Returns:
        Text.valueOf(this.get())
      • get

        public T get()
        Description copied from interface: Reference
        Returns the value this reference referes to.
        Specified by:
        get in interface Reference<T>
        Returns:
        the referent or null if not set.
      • set

        public void set(T value)
        Description copied from interface: Reference
        Sets the value this reference referes to.
        Specified by:
        set in interface Reference<T>
        Parameters:
        value - the reference value.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.