Skip to content
Commitwise
Menu

Reference type

A type whose variables hold a reference to a shared object, so assignment shares the object instead of copying it.

Definition

A variable of a reference type holds a link to an object that lives on the heap. Assigning it or passing it to a function copies the link, not the object, so every variable sees changes made through any of the others. Objects have identity: two objects can hold the same data and still be different objects. Swift classes and actors, and every non-primitive type in Kotlin and Java, are reference types.

In practice

val b = a with a Kotlin class instance, then b.name = "Marko": a.name is now "Marko" too, because a and b are the same object.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.