1
在Kotlin,我们有中间码我可以在没有`this`的情况下在自己的班级中应用中缀功能吗?
例如当我们有
fun Int.test(value: Int) {}
我们可以使用
1.test(2)
而当我们把缀
infix fun Int.test(value: Int) {}
我们可以为
1 test 2
利用A类,下面是好的
class myclass {
fun main() {
test(1)
}
fun test(value: Int) {}
}
但随着缀下面是不行的
class myclass {
fun main() {
test 1
}
infix fun test(value: Int) {}
}
显然,它必须有
class myclass {
fun main() {
this test 1
}
infix fun test(value: Int) {}
}
我可以省略this
,因为test
是类本身内通话?
“receiver functionName parameter
”
有没有办法解决它:
相关:https://stackoverflow.com/questions/35976405/infix-notation-and-with-does-not-work-as-i-expected – BakaWaii
可能重复[Infix notation and with(...)不按预期工作](https://stackoverflow.com/questions/35976405/infix-notation-and-with-does-not-work-as-i-expected) – zsmb13