---
title: "StateRecord"
description: "Snapshot local value of a state object."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
public abstract class StateRecord(
    /** The snapshot id of the snapshot in which the record was created. */
    internal var snapshotId: SnapshotId
)
```


Snapshot local value of a state object.


## Secondary Constructors

```kotlin
public constructor() : this(currentSnapshot().snapshotId)
```

```kotlin
public constructor(id: Int) : this(id.toSnapshotId())
```

## Functions

```kotlin
public abstract fun assign(value: StateRecord)
```


Copy the value into this state record from another for the same state object.


```kotlin
public abstract fun create(): StateRecord
```


Create a new state record for the same state object. Consider also implementing the `create`
overload that provides snapshotId for faster record construction when snapshot id is known.


```kotlin
public open fun create(snapshotId: Int): StateRecord
```


Create a new state record for the same state object and provided `snapshotId`. This allows to
implement an optimized version of `create` to avoid accessing `currentSnapshot` when snapshot
id is known. The default implementation provides a backwards compatible behavior, and should
be overridden if `StateRecord` subclass supports this optimization.


```kotlin
public open fun create(snapshotId: SnapshotId): StateRecord
```


Create a new state record for the same state object and provided `snapshotId`. This allows to
implement an optimized version of `create` to avoid accessing `currentSnapshot` when snapshot
id is known. The default implementation provides a backwards compatible behavior, and should
be overridden if `StateRecord` subclass supports this optimization.



