Resettable
A property delegate that instruments resetting it between opmode runs.
This is used in delegate properties. You must pass a function when constructing the resettable property that returns its default value.
val property: Type by Resettable {
// This is a function body.
// You can run anything in here.
val x = 1 + 2
// You do not need the `return` keyword.
// The last expression in the block, will be returned.
x + 2 // will return 5
}
Content copied to clipboard
Example
object MyAPI : API() {
// The starting value of someState is 10
private var someState: Int by Resettable { 10 }
}
Content copied to clipboard