How to create an instance of anonymous interface in Kotlin?

前端 未结 4 1167
北海茫月
北海茫月 2020-12-02 09:49

I have a third party Java library which an object with interface like this:

public interface Handler {
  void call(C context) throws Exception;
}
         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 10:06

    I had a case where I did not want to create a var for it but do it inline. The way I achieved it is

    funA(object: InterfaceListener {
                            override fun OnMethod1() {}
    
                            override fun OnMethod2() {}
    })
    

提交回复
热议问题