Java – The interface written by kotlin Why it is necessary to implement specific methods in the interface

The interface written by kotlin Why it is necessary to implement specific methods in the interface… here is a solution to the problem.

The interface written by kotlin Why it is necessary to implement specific methods in the interface

I wrote an interface with concrete methods in kotlin, and the class implementing it is asking whether to override it. If I write the same interface in Java, it works fine. Can I know what’s wrong with it?

In Kotlin

interface BottomSheet {

companion object{

val BOTTOMSHEET_ADAPTER:String="BOTTOMSHEET_ADAPTER"
    val FILTER_ADAPTER:String="FILTER_ADAPTER"

}

fun getBottomSheetAdapterInstance(context: Context?): BottomSheetAdapter? {
    return BottomSheetAdapter(context)
}

In Java

public interface BottomSheetJava {

default BottomSheetAdapter getBottomSheetAdapterInstance(Context context){
    return new BottomSheetAdapter(context);
}

In a gradient

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}

Solution

I see, we need to add

kotlinOptions {
jvmTarget = “1.8”
freeCompilerArgs = [‘-Xjvm-default=enable’]

}

and mark the specific method as

@JvmDefault

Related Problems and Solutions