Skip to content

Instantly share code, notes, and snippets.

@way2datta
Created September 11, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save way2datta/641c1d982d7442d47c78aacdf88bbb60 to your computer and use it in GitHub Desktop.
Save way2datta/641c1d982d7442d47c78aacdf88bbb60 to your computer and use it in GitHub Desktop.
Elvis operator in Kotlin
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