Ref<T> class sealed

A reference to an Object of type T.

How does the equality work?

void main() {
  final r1 = "nona".ref();
  final r2 = "nona".ref();
  final rc1 = r1.constRef();

  // false, because r1 and r2 hold an Object with the same
  // String content, but r1 and r2 are not references to
  // the same String Object.
  print(r1 == r2);

  // false, because r1 and r2 hold an Object with the same
  // String content, but r1 and r2 are not references to
  // the same String Object.
  print(r1.hashCode == r2.hashCode);

  // true, because r1 and r2 hold an Object with the same
  // String content. Here it does not matter that r1 and r2
  // are not references to the same String Object, because
  // we are only checking if the Strings have the same content.
  print(r1.value == r2.value);

  // true, because r1 and rc1 are a reference to the same
  // String Object. It does not matter that r1 is a MutableRef
  // and rc1 is a ConstRef, because only the underlying value
  // of references is compared.
  print(r1 == rc1);

  // true, because r1 and rc1 are a reference to the same
  // String Object. It does not matter that r1 is a MutableRef
  // and rc1 is a ConstRef, because only the underlying value
  // of references is used for calculating the hashCode.
  print(r1.hashCode == rc1.hashCode);
}
Implementers
Available Extensions

Constructors

Ref(T value)
Ref.constant(T value)
factory
Ref.mutable(T value)
factory

Properties

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

Methods

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.
override