Skip to content

Instantly share code, notes, and snippets.

@HWilliamgo
Created May 20, 2022 03:43
Show Gist options
  • Save HWilliamgo/d7e586a0d158ec6e29e784d20088af81 to your computer and use it in GitHub Desktop.
Save HWilliamgo/d7e586a0d158ec6e29e784d20088af81 to your computer and use it in GitHub Desktop.
[Kotlin elvis] #Kotlin
object StringProducer {
fun produce(): String? {
return "abc"
}
}
fun main() {
StringProducer.produce()?.let {
println(it)
} ?: run {
println("StringProducer.produce() return empty")
}
val s = StringProducer.produce()
if (s != null) {
println(s)
} else {
println("StringProducer.produce() return empty")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment