Created
February 27, 2020 10:09
-
-
Save Audhil/00cba526dcd648a16b5fe1ca84936c85 to your computer and use it in GitHub Desktop.
kotlin scope function
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
fun main() { | |
val valueIs = SomeObj() | |
val result = valueIs.also { | |
it.firstName = "Mohammed" | |
it.secondName = "Audhil" | |
} | |
println(valueIs) // SomeObj(firstName=Mohammed, secondName=Audhil) | |
println(result) // SomeObj(firstName=Mohammed, secondName=Audhil) | |
} | |
private class SomeObj { | |
var firstName: String? = null | |
var secondName: String? = null | |
override fun toString(): String { | |
return "SomeObj(firstName=$firstName, secondName=$secondName)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment