This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
public actual fun <T> lazy(initializer: () -> T): Lazy<T> = | |
SynchronizedLazyImpl(initializer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
override val value: T | |
get() { | |
val _v1 = _value | |
if (_v1 !== UNINITIALIZED_VALUE) { | |
@Suppress("UNCHECKED_CAST") | |
return _v1 as T | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
class Person { | |
var address: String by Delegates.observable("not entered yet!") { | |
property, oldValue, newValue -> | |
// update all existing shipments | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
protected void afterChange(@NotNull KProperty property, Object oldValue, Object newValue) { | |
// update all existing shipments | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { | |
val oldValue = this.value | |
if (!beforeChange(property, oldValue, value)) { | |
return | |
} | |
this.value = value | |
afterChange(property, oldValue, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
var address: String by Delegates.vetoable("") { | |
property, oldValue, newValue -> | |
newValue.length > 14 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
public final class Person$$special$$inlined$vetoable$1 extends ObservableProperty { | |
protected boolean beforeChange(@NotNull KProperty property, Object oldValue, Object newValue) { | |
Intrinsics.checkParameterIsNotNull(property, "property"); | |
String newValue = (String)newValue; | |
String var10001 = (String)oldValue; | |
int var7 = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
private class NotNullVar<T : Any>() : ReadWriteProperty<Any?, T> { | |
private var value: T? = null | |
public override fun getValue(thisRef: Any?, property: KProperty<*>): T { | |
return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
override fun setValue( | |
thisRef: Any?, | |
property: KProperty<*>, | |
value: String | |
) { | |
if (thisRef is Person) { | |
thisRef.updateCount++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
class ListWithTrash <T>( | |
private val innerList: MutableList<T> = ArrayList<T>() | |
) : MutableCollection<T> by innerList { | |
var deletedItem : T? = null | |
override fun remove(element: T): Boolean { | |
deletedItem = element | |
return innerList.remove(element) |