Ref<T> class abstract

Wraps an arbitary object, if caller method pass Ref to callee method, then any changes made on Ref.ref will affect caller too.

There are two ways to read / write the value:

var x = Ref<num?>(null);
x.ref;      // first way to read
x();        // second way to read

x.ref = 10; // first way to write
x(15);      // second way to write

Example:

void twice(Ref<num> x, Ref<num> y) {
  x.ref *= 2;
  y.ref *= 2;
}

void test() {
  var x = Ref<num>(5);
  var y = Ref<num>(7);

  twice(x, y);
  print(x.ref); // 10
  print(y.ref); // 14
}

Advanced Example:

void twiceAdvanced(Ref<num> x, Ref<num> y) {
  x(x() * 2);
  y(y() * 2);
}

void test() {
  var x = Ref<num>(5);
  var y = Ref<num>(7);

  twiceAdvanced(x, y);
  print(x()); // 10
  print(y()); // 14
}

Constructors

Ref(T ref)
factory

Properties

genericRuntimeType Type
no setter
hashCode int
The hash code for this object.
no setterinherited
ref ↔ T
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call([T ref]) → T
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

genericStaticType<S>(Ref<S> ref) Type