generics are not supported in -source 1.3

后端 未结 7 1193
太阳男子
太阳男子 2020-12-19 22:01

I have a problem while maven packaging. In this code:

public class LoginDialog extends Dialog {

    private final TextField customer;
                 


        
相关标签:
7条回答
  • 2020-12-19 22:07

    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.

    0 讨论(0)
  • 2020-12-19 22:15

    Generics were added in java 1.5. Your maven is compiling for java 1.3.

    This can be fixed in one of two ways.

    Remove generics so that you can compile for < 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:

            <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

    0 讨论(0)
  • 2020-12-19 22:16

    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.

    0 讨论(0)
  • 2020-12-19 22:23

    Android studio: It fixes by adding these below lines in the file app 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

    0 讨论(0)
  • 2020-12-19 22:30

    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:

    <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>
    
    0 讨论(0)
  • 2020-12-19 22:30

    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.

    0 讨论(0)
提交回复
热议问题