Skip to content

Instantly share code, notes, and snippets.

@mazzouzi
Last active June 1, 2022 09:01
Show Gist options
  • Save mazzouzi/da90f0dc9aa44cb00ded935e4c3f4d7c to your computer and use it in GitHub Desktop.
Save mazzouzi/da90f0dc9aa44cb00ded935e4c3f4d7c to your computer and use it in GitHub Desktop.
Stack vs Heap memory management
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