我正在尝试在基本的 android gradle 应用程序中使用钻石运算符:
ArrayList<TextView> texts = new ArrayList<>();
TextView tv = new TextView(this);
tv.setText("Hello World!");
texts.add(tv);
setContentView(texts.get(0));
不幸的是,这个简单的测试无法构建:
1> ... error: diamond operator is not supported in -source 1.6
1> ArrayList<TextView> texts = new ArrayList<>();
1> ^
1> (use -source 7 or higher to enable diamond operator)
在默认的 build.gradle.template 中,我只看到设置了这些编译选项:
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
如何告诉 Visual Studio 2015 和/或 gradle 使用版本 1.7 而不是 1.6? (哪里告诉我们要使用 1.6?)
谢谢!
最佳答案
我通过在位于 Visual Studio 2015 项目根目录的 build.gradle 文件中的 allprojects 中添加以下内容解决了这个问题:
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
不过,我仍然不确定为什么在没有这个的情况下将其设置为 1.6。
关于Visual Studio 2015 基本应用程序中的 Java 版本 1.7(Android、Gradle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38317821/