总结一下大佬们提出的方法:
-
在
kotlin
中可以使用when
关键字;val result = when { x in 1..10 -> x y.isOdd() -> "y is odd" s.contains("hello") -> s v is ViewGroup -> "child count: ${ v.getChildCount()
总结一下大佬们提出的方法:
在 kotlin
中可以使用 when
关键字;
val result = when {
x in 1..10 -> x
y.isOdd() -> "y is odd"
s.contains("hello") -> s
v is ViewGroup -> "child count: ${
v.getChildCount()