Skip to content

Instantly share code, notes, and snippets.

View yenerm's full-sized avatar

Murat Yener yenerm

  • Google
  • San Francisco
View GitHub Profile
@yenerm
yenerm / Lazy.kt
Last active November 9, 2020 21:14
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
public actual fun <T> lazy(initializer: () -> T): Lazy<T> =
SynchronizedLazyImpl(initializer)
<!-- 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;
}
}));
@yenerm
yenerm / Person$Lazy.java
Last active November 9, 2020 21:15
decompiled lazy()
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
@NotNull
private final Lazy fullname$delegate;
@yenerm
yenerm / Person.kt
Last active November 9, 2020 21:15
lazy() sample
<!-- Copyright 2020 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
val fullname: String by lazy() {
name + lastname
}
//...
}
<!-- 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++
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class FormatDelegate : ReadWriteProperty<Any?, String> {
private var formattedString: String = ""
override fun getValue(
thisRef: Any?,
property: KProperty<*>
): String {
@yenerm
yenerm / Person.kt
Last active February 15, 2022 11:41
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
var name: String by FormatDelegate()
var lastname: String by FormatDelegate()
var updateCount = 0
}
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, lastname: String) {
var name: String = name
set(value) {
field = value.toLowerCase().capitalize()
updateCount++
}
var lastname: String = lastname
<!-- Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 -->
class Person(name: String, var lastname: String) {
var name: String = name
set(value) {
field = value.toLowerCase().capitalize()
updateCount++
}
var updateCount = 0
public final class ListWithTrash implements Collection, KMutableCollection {
@Nullable
private Object deletedItem;
private final List innerList;
@Nullable
public final Object getDeletedItem() {
return this.deletedItem;
}