有没有办法从 java 类声明一个方法,以便可以将其作为 infix
进行调用来自 kotlin 的函数,如下所示:
public class Foo {
public void doFoo (String bar) {}
}
然后从 kotlin 文件
foo doFoo "bar"
最佳答案
Since Java has no way of marking methods for which it makes sense to use the operator syntax, Kotlin allows using any Java methods with the right name and signature as operator overloads and other conventions (
invoke()
etc.) Calling Java methods using the infix call syntax is not allowed.
关于java - 有没有办法将 java 方法声明为 kotlin 的中缀,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55023749/