Skip to content
Commitwise
Menu

Value type

Also called: Value semantics

A type whose values are copied on assignment, so each variable has its own independent data.

Definition

When you assign a value type to a new variable or pass it to a function, the data itself is copied. Changing the copy never changes the original, and two equal values are interchangeable. In Swift, struct, enum, tuples, String and the standard collections are value types. On the JVM only primitives (int, double, boolean and so on) are; Kotlin data classes and Java records are reference types that can behave like values when they are immutable.

In practice

var b = a with a Swift struct gives b its own copy: b.name = "Marko" leaves a.name unchanged.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.