Skip to content

Instantly share code, notes, and snippets.

@kozaxinan
Last active February 19, 2020 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kozaxinan/32d1d632e8f107bed5ef5cc3bde90678 to your computer and use it in GitHub Desktop.
Save kozaxinan/32d1d632e8f107bed5ef5cc3bde90678 to your computer and use it in GitHub Desktop.
Kotlin lazy vs object creator method
// Object creator method with extra referce
private var _name: String? = null
fun getName(): String {
if (_name == null) {
_name = "Sinan"
}
return _name!!
}
// Lazy version
val name: String by lazy { "Sinan" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment