class Foo(var x: Int) { /** * Value of this object is itself */ operator fun getValue(thisRef: Any?, property: KProperty<*>): Foo = this /* * Perform deep copy on set */ operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Foo) { this.x = value.x } } class ClassWithValueFoo { /* * Delegation results in value-type-like semantics */ var foo: Foo by Foo(5) } fun sample() { val test = ClassWithValueFoo() test.foo = Foo(10) // deep copy instead of reassignment }