Java source1.5 does not support diamond operator, please use source 7 or higher to enable diamond operator, what should I do?

Maven uses JDK1.5 to compile by default

The diamond operator, referring to a new feature of JDK1.7

List<String> list = new ArrayList<String>(); // 老版本写法
List<String> list = new ArrayList<>(); // JDK1.7写法

So Maven uses JDK1.5 to compile by default and definitely doesn't know this thing

You can add the following to your pom.xml

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Or you can configure the Maven compilation plugin directly in pom.xml, like the following

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324817776&siteId=291194637