Ref<T>#

A mutable box that holds one value of type T. A method that reports a result through an out parameter writes into it. In the public API that method is Patch#tryGetValue. Create an empty one with new Ref<>(), pass it in, then read value.

Declaration#

package org.dhtmlx.plen;

public class Ref<T>

Constructors#

Ref()#

public Ref()

Creates a holder with value set to null.

Ref(T value)#

public Ref(T value)

Creates a holder with value already set.

Name Type Description
value T The starting value. Can be null.

Fields#

value#

public T value

The held value. It's a plain public field: read it and assign it directly, with no getter or setter. Ref doesn't override equals, hashCode or toString, so two holders with the same value aren't equal.

Example#

import org.dhtmlx.plen.*;

public class RefExample {
    public static void main(String[] args) throws Exception {
        Patch<Double> duration = Patch.of(3.0);

        Ref<Double> out = new Ref<>();
        if (duration.tryGetValue(out)) {
            System.out.println("new duration: " + out.value); // new duration: 3.0
        }

        Patch<Double> untouched = Patch.missing();
        System.out.println(untouched.tryGetValue(out)); // false
        System.out.println(out.value);                  // null
    }
}