3

我在 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;

我有一个错误,如:

[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

这可能是什么原因?

4

7 回答 7

9

Java 1.5 中添加了泛型。您的 maven 正在为 java 1.3 编译。

这可以通过以下两种方式之一来解决。

删除泛型,以便您可以针对 < 1.5 进行编译

更改 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>

这告诉 maven 为 1.5 编译

于 2013-04-01T15:31:14.727 回答
3

您需要告诉 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>
于 2013-04-01T15:31:33.970 回答
1

使用 编译代码时-source 1.3,编译器不支持断言、泛型或 JDK 1.3 之后引入的其他语言特性。

于 2013-04-01T15:29:29.343 回答
1

Android studio:它通过在文件 app build.gradle 中添加以下几行来修复

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

注意:使用最新的java版本,这里我使用的是java 8

于 2019-01-23T06:58:53.113 回答
0

您要么需要更改设置,以便将源设置为 1.5+,要么从代码中删除泛型:

private final TextField customer;
于 2013-04-01T15:28:02.363 回答
0

泛型只是作为 Java 5 中的一项功能引入的,因此在使用 3 进行编译时,将不允许使用泛型。如果您想了解有关泛型的更多信息,请查看此处。因此,您需要使用 5 或更高版本进行编译,或者停止使用泛型。

于 2013-04-01T15:32:42.147 回答
0

如果您没有使用 maven 并在 Intellij 编辑器中遇到类似问题,可能值得检查项目设置。即使您定义了正确的 JDK,更改“项目语言级别”并且可以配置 5 起。

于 2019-05-26T14:10:39.497 回答