Created
January 9, 2018 22:23
-
-
Save Allan-Gong/de32be7cfa3e541d02f33b776b488dc9 to your computer and use it in GitHub Desktop.
apply V.S with in Kotlin
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
// Usage of apply: do something with an object and return it | |
fun getDeveloper(): Developer { | |
return Developer().apply { | |
developerName = "Amit Shekhar" | |
developerAge = 22 | |
} | |
} | |
// Usage of with: transform A -> B | |
fun getPersonFromDeveloper(developer: Developer): Person { | |
return with(developer) { | |
Person(developerName, developerAge) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment