Created
February 27, 2020 10:13
-
-
Save Audhil/93a40db33b3e186d3813a1d9e588e5a5 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.apply { | |
this.firstName = "Mohammed" | |
this.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