Last active
February 19, 2020 14:27
-
-
Save kozaxinan/32d1d632e8f107bed5ef5cc3bde90678 to your computer and use it in GitHub Desktop.
Kotlin lazy vs object creator method
This file contains hidden or 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
// 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