问题遇到的现象和发生背景
在别人的代码中看到了一段关于floorDiv的代码,写法很奇怪,但是不知道为什么可以这么写,不知道是不是简写
问题相关代码,请勿粘贴截图
private fun Int.floorMod(other: Int): Int = when(other) {
0 -> this
else -> this - (this.floorDiv(other)) * other
}
private fun Int.floorMod1(other: Int): Int = when(other) {
0 -> this
else -> this - floorDiv(other) * other
}
运行结果及报错内容
这两个方法的else是一样的,这是什么简写方法