[Canonical page](<https://docs.dhtmlx.com/planning-engine/java/api/support/ref/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# 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`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/patch.md#trygetvalue>). Create an empty one with `new Ref<>()`, pass it in, then read `value`.

## Declaration

```java
package org.dhtmlx.plen;

public class Ref<T>
```

## Constructors

### Ref()

```java
public Ref()
```

Creates a holder with `value` set to `null`.

### Ref(T value)

```java
public Ref(T value)
```

Creates a holder with `value` already set.

| Name | Type | Description |
|---|---|---|
| `value` | `T` | The starting value. Can be `null`. |

## Fields

### value

```java
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

```java
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
    }
}
```

## Related

- [`Patch`](<https://docs.dhtmlx.com/planning-engine/java/api/changes/patch.md#trygetvalue>) - `tryGetValue` writes into a `Ref`
- [`SortedDict`](<https://docs.dhtmlx.com/planning-engine/java/api/support/sorted-dict.md#trygetvalue>) - another `tryGetValue` that takes a `Ref`
- [Records, ids and dates](<https://docs.dhtmlx.com/planning-engine/java/records-ids-and-dates.md#patch-fields>) - reading patch fields
