java -source 1.3 不支持泛型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15746264/
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
generics are not supported in -source 1.3
提问by Nikitin Mikhail
I have a problem while maven packaging. In this code:
Maven 打包时遇到问题。在这段代码中:
public class LoginDialog extends Dialog {
private final TextField<String> customer;
^here
private final TextField<String> login1;
private final TextField<String> password1;
private final MainController controller= new MainController();
private String customerId;
private String login;
private String password;
I have an error like:
我有一个错误,如:
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
...src/main/java/com/messagedna/web/client/widget/LoginDialog.java:[19,27] error: generics are not supported in -source 1.3
what may be the reason of this?
这可能是什么原因?
回答by Boris the Spider
Generics were added in java 1.5. Your maven is compiling for java 1.3.
泛型是在 java 1.5 中添加的。您的 Maven 正在为 Java 1.3 编译。
This can be fixed in one of two ways.
这可以通过以下两种方式之一解决。
Remove generics so that you can compile for < 1.5
删除泛型,以便您可以编译 < 1.5
Change the maven configuration to compile for a newer version of java. You should be able to edit your compiler plugin in your pom:
更改 maven 配置以针对较新版本的 java 进行编译。你应该能够在你的 pom 中编辑你的编译器插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
This tells maven to compile for 1.5
这告诉 maven 编译 1.5
回答by Matt Coarr
You need to tell the maven compiler plugin that your code is using a recent java version. For instance, if you are using java 7, to the following:
您需要告诉 Maven 编译器插件您的代码使用的是最新的 Java 版本。例如,如果您使用的是 java 7,请执行以下操作:
<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>
回答by Shyam Kumar
Android studio: It fixes by adding these below lines in the file app build.gradle
Android studio:它通过在文件 app build.gradle 中添加以下几行来修复
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Note: use the latest java version, here I'm using java 8
注意:使用最新的java版本,这里我使用的是java 8
回答by NPE
When you compile your code with -source 1.3
, the compiler does not support assertions, generics, or other language features introduced after JDK 1.3.
使用 编译代码时-source 1.3
,编译器不支持断言、泛型或 JDK 1.3 之后引入的其他语言功能。
回答by S.P.
If you are not using maven and facing similar issue in Intellij editor, probably worth to check Project Settings. Even if you define Proper JDK, change the "Project language level" and can configure 5 onward.
如果您不使用 maven 并在 Intellij 编辑器中遇到类似问题,可能值得检查项目设置。即使您定义了正确的 JDK,更改“项目语言级别”也可以配置 5 个。
回答by Uncle Iroh
You either need to change your settings so that you're source is set to 1.5+ or remove the generics from your code:
您要么需要更改设置,以便将源设置为 1.5+ 或从代码中删除泛型:
private final TextField customer;
回答by brent777
Generics were only introduced as a feature in Java 5, so when compiling using 3, generics will not be permitted. If you want more info about generics, look here. So you need to either compile using 5 or later or stop using generics.
泛型仅作为 Java 5 中的一项功能引入,因此在使用 3 进行编译时,将不允许使用泛型。如果你想了解更多关于泛型的信息,请看这里。因此,您需要使用 5 或更高版本进行编译或停止使用泛型。