Skip to content

Instantly share code, notes, and snippets.

Avatar

Murat Yener yenerm

View GitHub Profile
@yenerm
yenerm / Person.kt
Last active Nov 9, 2020
lazy() sample
View Person.kt
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
val fullname: String by lazy() {
name + lastname
}
//...
}
@yenerm
yenerm / Person$Lazy.java
Last active Nov 9, 2020
decompiled lazy()
View Person$Lazy.java
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
@NotNull
private final Lazy fullname$delegate;
View Person$Lazy.java
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
this.fullname$delegate = LazyKt.lazy((Function0)(new Function0() {
@NotNull
public final String invoke() {
return name + lastname;
}
}));
View Lazy.kt
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public actual fun <T> lazy(initializer: () -> T): Lazy<T> =
SynchronizedLazyImpl(initializer)
View Lazy.kt
<!-- 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
}
View Person.kt
<!-- 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
}
}
View $ObservableProperty.kt
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
protected void afterChange(@NotNull KProperty property, Object oldValue, Object newValue) {
// update all existing shipments
}
View ObservableProperty.kt
<!-- 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)
View Person.kt
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
var address: String by Delegates.vetoable("") {
property, oldValue, newValue ->
newValue.length > 14
}
View Person$$special$$inlined$vetoable$1.java
<!-- 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;