eclipse 错误:-source1.5 不支持菱形运算符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29625713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error: diamond operator is not supported in -source1.5
提问by sudarshan
I am creating an app which uses cordova ionic and angular and for barcode scanning i am using native and able to integrate with the javascript code.If I run the project using eclipse IDE its working fine but if I do ionic run android - getting the above error - diamond operator is not supported in - source 1.5
我正在创建一个使用cordova ionic和angular的应用程序,用于条形码扫描我使用的是本机并能够与javascript代码集成。如果我使用eclipse IDE运行该项目,它工作正常,但如果我运行ionic run android - 得到上述内容错误 - 源 1.5 不支持菱形运算符
For native i used this link https://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/and its working fine.
对于本机,我使用了此链接https://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcode-scanner-into-your-android-app-natively-using-eclipse/并且它工作正常。
Can anyone help on this issue?
任何人都可以帮助解决这个问题吗?
回答by Swarit Agarwal
Try to add apache plugnin to your Pom.xml under Build tag as @Sudarshan mentioned.
尝试将 apache 插件添加到您的 Pom.xml 下的 Build 标记下,如@Sudarshan 所述。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
This would resolve issue
这将解决问题
回答by Ceiling Gecko
You are using <>
which is not supported by the java source you are using since it got added only in Java 1.7
您正在使用<>
的 Java 源不支持它,因为它仅在 Java 1.7 中添加
Find the places in your source code where you are using <>
and properly specify the generic that is implied.
在源代码中找到您正在使用的位置,<>
并正确指定隐含的泛型。
e.g. if it was:
例如,如果它是:
List<String> myList = new ArrayList<>();
rewrite it as
将其改写为
List<String> myList = new ArrayList<String>();
Note:Although diamond operator is a handy shortcut, I'd recommend to always specify full generics as it not only adds to readability, it also does not create a 1.7+ dependency on your source. (Which as we can see can sometimes lead to problems.)
注意:虽然菱形运算符是一个方便的快捷方式,但我建议始终指定完整的泛型,因为它不仅增加了可读性,而且不会对您的源产生 1.7+ 依赖性。(正如我们所见,这有时会导致问题。)
回答by Charlie
**Right click on project -> Properties -> Project Facets -> tick Java, select 1.7
**右击项目-> 属性-> Project Facets -> 勾选Java,选择1.7
回答by Marvin Glenn Lacuna
+1 to @Swarit Agarwal answer, below is the full content of the pom.xml for easy reference.
+1 对@Swarit Agarwal 的回答,以下是 pom.xml 的完整内容,以供参考。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>order-rest-marvin</groupId>
<artifactId>order-rest-marvin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.7.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
</dependencies>
<!-- to resolve the issue about maven plugin not supported (older versions) -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>