【问题标题】:Android Studio: Extension Methods are not supported at this language levelAndroid Studio:此语言级别不支持扩展方法
【发布时间】:2016-05-17 12:43:20
【问题描述】:

以下代码产生了错误 “此语言级别不支持扩展方法” 在安卓工作室:

public interface Test {
 static String Test2(String A) {
    return "";
    }
}

AS 2.0 Beta 2

我做错了什么?

【问题讨论】:

    标签: android-studio-2.0


    【解决方案1】:

    您正在尝试使用 static interface method,这是 Java 8 中的一项新功能。 在Android N 之前,Android 不支持它。有关更多信息,请参阅 Android 指南中的 Use Java 8 Language Features

    目前还有BUG

    您必须使用 Java 8 按照上述说明进行编译。 以下是build.gradle 的示例:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 'android-N'
        buildToolsVersion "24.0.0-rc3"
    
        defaultConfig {
            applicationId "example.com.examplejdk8"
            minSdkVersion 24
            targetSdkVersion 'N'
            versionCode 1
            versionName "1.0"
            jackOptions {
                enabled true
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.0.0-alpha2'
        compile 'com.android.support:design:24.0.0-alpha2'
    }
    

    【讨论】:

      猜你喜欢
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-15
      • 2015-05-26
      • 1970-01-01
      • 2016-05-05
      相关资源
      最近更新 更多