gpt4 book ai didi

java - 为什么Android Studio 3.0不支持默认和静态接口(interface)方法

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:44:12 27 4
gpt4 key购买 nike

为什么 Android Studio 3.0 不支持 java 8 的[默认和静态接口(interface)方法]?

代码总是得到错误提示。

the demo code

build.gradle 设置:

compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.dreamzone.mtime"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"

}

但 android studio 文档显示它可以兼容任何 api 级别。 https://developer.android.com/studio/write/java8-support.html android studio doc

最佳答案

您需要通过 android 闭包内的 compileOptions 闭包在模块的 build.gradle 文件中设置 Java 8 兼容性:

apply plugin: 'com.android.application'

android {

// other good stuff here

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

关于java - 为什么Android Studio 3.0不支持默认和静态接口(interface)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47488126/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com