Last active
June 1, 2022 09:01
-
-
Save mazzouzi/da90f0dc9aa44cb00ded935e4c3f4d7c to your computer and use it in GitHub Desktop.
Stack vs Heap memory management
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
fun main() { | |
val actor = Actor("Will", "Smith", 53) // (1) | |
val forName = actor.forName // (2) | |
val funFact = actor.getFunFact(forName) // (3) | |
println(funFact) | |
} | |
class Actor(val forName: String, val name: String, val age: Int) { | |
fun getFunFact(key: String?): String? = funFacts[key] // (3') | |
} | |
private val funFacts = mutableMapOf( | |
"Will" to "slapped Chris Rock in the face at the Academy Awards" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment