Using kotlin extension function in Java code

Tags: , , ,

I have created an extension function for listening to click listener for buttons, when I try to access it from Java code it does not work,

Cannot access clicks() from java file, this is what I tried

Can you please suggest how to resolve this.

Thanks R

File – Extension.kt

   fun Button.clicks(): Flow<Unit> = callbackFlow {
        setOnClickListener {
        awaitClose { setOnClickListener(null) }

In my java code –

    public Flow<Void> getStartFillingObservableFlow() {
        return dataViewHolder.btnStartFilling.clicks(); //CLICKS IS NOT. RECOGNISED


    public Button btnStartFilling;


Extension functions usually compiles to statics functions so you can invoke them like this:


Source: stackoverflow