Skip to content

Instantly share code, notes, and snippets.

View skydoves's full-sized avatar
💡
Practice is the only shortcut

Jaewoong Eum skydoves

💡
Practice is the only shortcut
View GitHub Profile
@skydoves
skydoves / 13_LambdaCallDecompiled.java
Created February 17, 2026 01:14
Decompiled Lambda - Anonymous Class Generation
Function1<Integer, Integer> lambda = new Function1<Integer, Integer>() {
@Override
public Integer invoke(Integer it) {
return it * 2;
}
};
int result = higherOrderExample(lambda);
@skydoves
skydoves / 12_LambdaCall.kt
Created February 17, 2026 01:14
Kotlin Lambda Call
val result = higherOrderExample { it * 2 }
@skydoves
skydoves / 11_HigherOrderFunctionDecompiled.java
Created February 17, 2026 01:14
Decompiled Higher-Order Function - Function1 Interface
int higherOrderExample(Function1<Integer, Integer> operation) {
return operation.invoke(10);
}
@skydoves
skydoves / 10_HigherOrderFunction.kt
Created February 17, 2026 01:14
Kotlin Higher-Order Function
fun higherOrderExample(operation: (Int) -> Int): Int {
return operation(10)
}
@skydoves
skydoves / 09_ValueClassBoxing.kt
Created February 17, 2026 01:14
Value Class Boxing Scenarios in Kotlin
val id1: Any = UserId("abc") // Stored as Any, forces boxing
val id2: UserId? = UserId("def") // Nullable type can force boxing
val listOfIds = listOf(UserId("1")) // Generic collection, forces boxing
@skydoves
skydoves / 08_ValueClassDecompiled.java
Created February 17, 2026 01:14
Decompiled Value Class - Java Bytecode
public final class IdKt {
// The function takes the PRIMITIVE type directly
public static final void processId(String userId) {
String var1 = "Processing user with ID: " + userId;
System.out.println(var1);
}
public static final void main() {
// No UserId object allocated
String myId = UserId.constructor_impl("user-123");
@skydoves
skydoves / 07_ValueClass.kt
Created February 17, 2026 01:14
Kotlin Value Class with @JvmInline
@JvmInline
value class UserId(val id: String)
fun processId(userId: UserId) {
println("Processing user with ID: ${userId.id}")
}
fun main() {
val myId = UserId("user-123")
processId(myId)
@skydoves
skydoves / 06_SafePublicationLazyImpl.kt
Created February 17, 2026 01:14
SafePublicationLazyImpl - LazyThreadSafetyMode.PUBLICATION
// simplified
override val value: T
get() {
if (_value !== UNINITIALIZED_VALUE) {
return _value as T
}
val initializerValue = initializer
if (initializerValue != null) {
val newValue = initializerValue()
if (valueUpdater.compareAndSet(this, UNINITIALIZED_VALUE, newValue)) {
@skydoves
skydoves / 05_SynchronizedLazyImpl.kt
Created February 17, 2026 01:14
SynchronizedLazyImpl - LazyThreadSafetyMode.SYNCHRONIZED
// simplified
override val value: T
get() {
if (_value !== UNINITIALIZED_VALUE) {
return _value as T // Fast path: no lock needed
}
return synchronized(lock) {
if (_value !== UNINITIALIZED_VALUE) {
_value as T // Second check inside lock
} else {
@skydoves
skydoves / 04_UnsafeLazyImpl.kt
Created February 17, 2026 01:14
UnsafeLazyImpl - LazyThreadSafetyMode.NONE
// simplified
override val value: T
get() {
if (_value === UNINITIALIZED_VALUE) {
_value = initializer!!()
initializer = null
}
return _value as T
}