Created
September 11, 2021 14:05
-
-
Save way2datta/641c1d982d7442d47c78aacdf88bbb60 to your computer and use it in GitHub Desktop.
Elvis operator 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
fun main(args: Array<String>) { | |
val arnav = Person(); | |
println(arnav); | |
arnav.name = "Arnav Kale"; | |
println(arnav); | |
} | |
class Person { | |
var name: String? = null | |
override fun toString(): String { | |
var derievedName: String = this.name ?: "Unknown"; | |
return "My name is $derievedName"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment