Java – Why can’t I import the java.util.function package in Android Studio?

Why can’t I import the java.util.function package in Android Studio?… here is a solution to the problem.

Why can’t I import the java.util.function package in Android Studio?

In Android Studio 2.0 Beta 7, I can see this class “Consumer” in java.util.function.consumer.
enter image description here

But I can’t import it in Android Studio, why?
I did these methods in Gradle as follows. I’m sure I’m using Java8 because I can use the default keyword in the interface, which is new in Java8.

Can anyone tell me why?
This behavior also occurs with the java.util.stream package.

In gradients:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Solution

The package java.util.function is now available in the Android runtime environment, so you can import it. To find out which classes/packages you can use in the Android runtime, look up the reference here

Related Problems and Solutions