简体   繁体   English

从java调用kotlin中的方法

[英]call method in kotlin from java

I am using a library written in kotlin and I need to access methods on it.我正在使用一个用kotlin编写的库,我需要访问它的方法。

This is the signature of kotlin method:这是 kotlin 方法的签名:

 public final fun connect(userId: kotlin.String, onFailure: (kotlin.String) -> kotlin.Unit, onSuccess: (UserEntity) -> kotlin.Unit): kotlin.Unit {}

How can i call this method from java?我如何从java调用这个方法?

EDIT编辑

I already tried this:我已经试过了:

new Function1<String, Unit>() {
                        @Override
                        public Unit invoke(String s) {
                            return null;
                        }
                    }

Try next code:尝试下一个代码:

FileKt.connect("", s -> { 
            //do something when Failure
            return null;
        },
        o -> {
            //do something when Success
            return null;
        });

where FileKt - name of the file where connect function is defined.其中FileKt - 定义connect函数的文件的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM