在别人的代码中看到了一段关于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是一样的,这是什么简写方法
哪里有简写?这不是正常的计算吗!this.就是调用函数的对象。
这样写感觉 有点绕