简体   繁体   English

-source 1.3不支持泛型

[英]generics are not supported in -source 1.3

I have a problem while maven packaging. 我在进行Maven包装时遇到问题。 In this code: 在此代码中:

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? 这可能是什么原因?

Generics were added in java 1.5. 泛型是在Java 1.5中添加的。 Your maven is compiling for java 1.3. 您的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. 更改Maven配置,以针对Java的较新版本进行编译。 You should be able to edit your compiler plugin in your pom: 您应该可以在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编译

You need to tell the maven compiler plugin that your code is using a recent java version. 您需要告诉Maven编译器插件您的代码正在使用最新的Java版本。 For instance, if you are using java 7, to the following: 例如,如果您使用的是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>

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

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

private final TextField customer;

Generics were only introduced as a feature in Java 5, so when compiling using 3, generics will not be permitted. 泛型仅在Java 5中作为功能引入,因此在使用3进行编译时,将不允许泛型。 If you want more info about generics, look here . 如果您需要有关泛型的更多信息,请参见此处 So you need to either compile using 5 or later or stop using generics. 因此,您需要使用5或更高版本进行编译,或者停止使用泛型。

Android studio: It fixes by adding these below lines in the file app build.gradle Android Studio:通过在文件应用程序build.gradle中添加以下这些行来修复

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

If you are not using maven and facing similar issue in Intellij editor, probably worth to check Project Settings. 如果您不使用maven并在Intellij编辑器中遇到类似问题,则可能值得检查“项目设置”。 Even if you define Proper JDK, change the "Project language level" and can configure 5 onward. 即使定义了正确的JDK,也可以更改“项目语言级别”,并且可以配置5以上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM