Idea报错source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
2018-03-26 11:56
501 查看
Error:(71, 35) 错误: -source 1.6 中不支持 diamond 运算符(请使用 -source 7 或更高版本以启用 diamond 运算符)
这个错误对应程序里的代码是:
一般正确的写法是在声明的时候指定类型,也就是:List<PublicBlogListBean> _hotDatas = new ArrayList<PublicBlogListBean>();
但是在JDK 1.7里新增了一个新特性: 增强对通用实例创建(diamond)的类型推断 :
类型推断是一个特殊的烦恼,下面的代码:
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
通过类型推断后变成:
Map<String, List<String>> anagrams = new HashMap<>();
这个<>被叫做diamond(钻石)运算符,这个运算符从引用的声明中推断类型。
也就是说JDK1.7支持这种类型推断后,在声明_hotDatas 时new ArrayList<>里可以不需要加上PublicBlogListBean类型
截图中的错误也提示了:-soure1.6中不支持diamond运算符,Diamond types are not supported at this language level。说明目前使用的JDK版本不支持,但是Project此时的JDK路径正是1.7的版本,这...一、按下图箭头步骤操作
按以上步骤操作应用后就能解决问题,如果不能就把Project Structure中所有有关版本的都调整为1.7及以上。还有调整java compiler的版本
二、事实上项目里还没有对module做源码兼容性的配置,即设置 Source Compatibility和Target Compatibility为1.7:
点击ok会后gradle重新构建,确定reload Project下就好啦~
三、也可以在build.gradle里直接配置:
四、也可以在Maven的pom.xml里配置:这样任何人从svn或git下下来的代码都无需操作一或二步骤<project xmlns="...">
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
这个错误对应程序里的代码是:
一般正确的写法是在声明的时候指定类型,也就是:List<PublicBlogListBean> _hotDatas = new ArrayList<PublicBlogListBean>();
但是在JDK 1.7里新增了一个新特性: 增强对通用实例创建(diamond)的类型推断 :
类型推断是一个特殊的烦恼,下面的代码:
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
通过类型推断后变成:
Map<String, List<String>> anagrams = new HashMap<>();
这个<>被叫做diamond(钻石)运算符,这个运算符从引用的声明中推断类型。
也就是说JDK1.7支持这种类型推断后,在声明_hotDatas 时new ArrayList<>里可以不需要加上PublicBlogListBean类型
截图中的错误也提示了:-soure1.6中不支持diamond运算符,Diamond types are not supported at this language level。说明目前使用的JDK版本不支持,但是Project此时的JDK路径正是1.7的版本,这...一、按下图箭头步骤操作
按以上步骤操作应用后就能解决问题,如果不能就把Project Structure中所有有关版本的都调整为1.7及以上。还有调整java compiler的版本
二、事实上项目里还没有对module做源码兼容性的配置,即设置 Source Compatibility和Target Compatibility为1.7:
点击ok会后gradle重新构建,确定reload Project下就好啦~
三、也可以在build.gradle里直接配置:
四、也可以在Maven的pom.xml里配置:这样任何人从svn或git下下来的代码都无需操作一或二步骤<project xmlns="...">
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
相关文章推荐
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 异常: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 运行开源项目,报错Error:(48, 37) 错误: -source 1.6 中不支持 diamond 运算符,请使用-source 7或者更高版本已启用diamond运算符
- Error:(54, 61) 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- Error:(54, 61) 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 兔子--Error:(88, 35) 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- Error:(70, 41) 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 安卓学习笔记---使用AndroidStudio出现的问题错误(错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算)
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 错误:-source 1.5 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- 1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符
- 关于Maven installed出现source 1.5 中不支持 diamond 运算符问题(请使用 -source 7 或更高版本以启用 diamond 运算符)
- 1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符,怎么办?
- -source 1.5 中不支持 diamond 运算符 [ERROR] (请使用 -source 7 或更高版本以启用 diamond 运算符)
- Maven install时抛出“1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符”
- IDEA Error:(71, 35) 错误: -source 1.6 中不支持 diamond 运算符(请使用 -source 7 或更高版本以启