Java1.8 new features, such as support for lambda expressions, parent inference, etc., this article describes the new features of 1.8, interested students can point to see. However, since Androidstudio does not directly support Java1.8, we need to manually import some plug-ins to support 1.8:
First add plugins at the outermost layer of the app Build.gradle:
Apply plugin: ' Me.tatarka.retrolambda '
Then find the dependencies of the Build.gradle file and add the following code to this layer:
Retrolambdaconfig "net.orfjackal.retrolambda:retrolambda:${version number}"//According to the need to go to the official website view version number, the author is "2.3.0"
Then go to the Build.gradle in the project layer and find the dependencies layer and add the code:
Classpath ' me.tatarka:gradle-retrolambda:3.2.4 '
This will enable Java 1.8 Support, back to the app layer in the Build.gradle, under the Android–>defaultconfig layer to add the compilation settings can:
compileoptions {
sourcecompatibility javaversion.version_1_8
targetcompatibility JavaVersion.VERSION_1_8
}