解决:Java source1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符

Maven默认用的是JDK1.5去编译

diamond运算符,指的是JDK1.7的一个新特性

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

所以Maven默认使用JDK1.5去编译是不认识这个东西的,针对这种问题,在网上找了三种解决方案:

Ⅰ :在项目pom.xml中加入下面的配置即可

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

Ⅱ:直接在模块pom.xml中配置Maven的编译插件也是可以的,像下面这样:

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

  

Ⅲ:另外还有一种最终的解决方案,适用于idea下配置Maven的所有项目:

在配置的maven安装包的setting.xml中的profiles标签中加入以下标签

<profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>

这样之后就不会出现每次新创建的maven项目默认JDK版本都是1.5版本的了。

备注:

第二种解决方案亲测有效。有的人电脑没有这段代码后会打包失败,有的电脑却不会,暂时不知什么原因。

原文地址:https://www.cnblogs.com/059212315/p/12122820.html

时间: 2024-08-08 20:41:01

解决:Java source1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符的相关文章

错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)

今天晚上在AS上运行校长项目时,报错如下: Error:(71, 35) 错误: -source 1.6 中不支持 diamond 运算符(请使用 -source 7 或更高版本以启用 diamond 运算符) 这个错误对应程序里的代码是: 一般正确的写法是在声明的时候指定类型,也就是: List<PublicBlogListBean>  _hotDatas = new ArrayList<PublicBlogListBean>(); 但是在JDK 1.7里新增了一个新特性: 增强

Error:(18, 51) java: -source 1.5 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)

问题:主要是因为jdk版本不一样 解决: 方法一:List<String> list=new ArrayList<Stirng>(); 方法二:重新安装jdk8的版本(安装和配置环境变量) File->Project Structure->Modules->Language level 选择为7的版本,主要是因为JDK版本不支持 修改之后又出现下面的问题 问题: 解决: 结果: 原文地址:https://www.cnblogs.com/ysgcs/p/960891

错误:在maven install是抛出 “1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符”

Maven默认用的是JDK1.5去编译 diamond运算符,有的书翻译为菱形,有的书写的是钻石语法,指的是JDK1.7的一个新特性 List<String> list = new ArrayList<String>(); // 老版本写法 List<String> list = new ArrayList<>(); // JDK1.7写法 所以Maven默认使用JDK1.5去编译肯定是不认识这个东西的 你可以在pom.xml中加入下面的东西即可 <p

Maven报错:“请使用 -source 7 或更高版本以启用 diamond 运算符”

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building storm-kafka-test 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO

转发:maven打包时始终出现以下提示:-source 1.3 中不支持泛型(请使用 -source 5 或更高版本以启用泛型)

maven打包时始终出现以下提示: 1.-source 1.3 中不支持泛型(请使用 -source 5 或更高版本以启用泛型)List<User> userList= new ArrayList<User>(); 2.-source 1.3 中不支持注释(请使用 -source 5 或更高版本以启用注释)@WebService(endpointInterface = "com.webservice.service.LoadService") 而用命令mvn -

maven-source 1.3 中不支持注释请使用 -source 5 或更高版本以启用注释

解决办法:在pom里 加上以下代码 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</

使用maven编译的时候提示 maven-source 1.3 中不支持注释请使用 -source 5 或更高版本以启用注释的错误。

在编译的模块的pom文件中加上 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</ta

IDEA java:-source 1.5中不支持diamond运算符,请使用-source7或更高版本以启动diamond运算符

IDEA java:-source 1.5中不支持diamond运算符,请使用-source7或更高版本以启动diamond运算符 产生这个问题的原因是,project structure中对于JDK版本的设置和配置环境的时候选择的JDK版本不兼容. 所以修改方法为: file-project structure 将Language level修改成7以上的就可以. 原文地址:https://www.cnblogs.com/wobushitiegan/p/12254886.html

-source 1.5 中不支持泛型(请使用-source5或更高版本)

Idea中maven--compile时报错     -source 1.5 中不支持泛型(请使用-source5或更高版本) 解决办法 在项目的pom.xml中,添加 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <config