kotlin-运行vs猫王运算符-有什么区别? [英] kotlin - run vs elvis operator - what is the difference?
本文介绍了kotlin-运行vs猫王运算符-有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
im试图了解kotlin中以下两段代码之间的区别:
im trying to understand the difference between the following two pieces of code in kotlin:
myVar?.let { print(it) } ?: run { print("its null folks") }
vs
myVar?.let { print(it) } ?: print("its null folks")
它们等效吗?运行只是为了使我们可以使用代码块,而另一个仅用于单个语句?
are they equivalent ? is run just so we can use a block of code and the the other is for just a single statement ?
推荐答案
是的,它们是等效的. run
允许您在elvis运算符的右侧使用多个语句;在这种情况下,只有一个,因此不需要run
.
Yes, they are equivalent. run
allows you to use multiple statements on the right side of an elvis operator; in this case there's only one, so run
is not needed.
这篇关于kotlin-运行vs猫王运算符-有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文