Is it possible to use default interface implementation in Android < API 24?

a_subscriber :

Android Studio 2.3.3, Java 8

I create Android app for Android 4.0+

In my app/build.gradle:

...
minSdkVersion 15
targetSdkVersion 26

I want to use default interface implementation (from Java 8). So I create the tnext class:

public interface DefaultCallback {

    public default void onResponse(Call<T> var1, Response<T> var2) {

    }
}

but I get compile error:

Default method required API level 24 (current min is 15)

So the question is:

Can I use deafult interface implementation on Android < API 24?

dboof :

Depending on what your minSdk version is you may need to add the following to your app's or module's build.gradle file:

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

See https://developer.android.com/studio/write/java8-support.html#supported_features for more details

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=432605&siteId=1