Kotlin: Interface … does not have constructors

前端 未结 7 1165
长情又很酷
长情又很酷 2020-12-04 16:14

I am converting some of my Java code to Kotlin and I do not quite understand how to instantiate interfaces that are defined in Kotlin code. As an example, I have an interfac

7条回答
  •  鱼传尺愫
    2020-12-04 16:42

    if you have Java class like this :

    recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new RecyclerTouchListener.ClickListener()
            {
                  //Your Code
            }));
    

    you shoud convert this code from Java to Kotlin like this :

    override fun showJozList (list : List) {
            adapter.addData(list)
            jozlist_recycler.addOnItemTouchListener(RecyclerTouchListener(
                    activity ,
                    jozlist_recycler ,
                    object : RecyclerTouchListener.ClickListener
                        {
                              //Your Code
                        }))
    

    convert Java Interface :

    new RecyclerTouchListener.ClickListener()
    

    to Kotlin Interface Style:

    object : RecyclerTouchListener.ClickListener
    

提交回复
热议问题