How to change from -source 1.6 to -source 7 in Int

2019-02-05 16:58发布

I' trying to build a in IntelliJ IDEA project that is not mine and I got the following error:

java: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator)

How do I change this setting in IntelliJ IDEA?

7条回答
在下西门庆
2楼-- · 2019-02-05 17:27

I know the OP uses IntelliJ IDEA, but Android Studio is based on IntelliJ IDEA, so I wanna say one more word.

If you use Android Studio, command+;(for Mac) or File->Project Structure, then in the open window follow the settings:

enter image description here

查看更多
我想做一个坏孩纸
3楼-- · 2019-02-05 17:27

For me, changing the Language Level in Project Structure and restarting IDEA didn't help.

I had to edit the build.gradle in core module and change the source compatibility from 1.6 to 1.7:

apply plugin: "java"

sourceCompatibility = 1.7 //changed from 1.6
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

sourceSets.main.java.srcDirs = [ "src/" ]


eclipse.project {
    name = appName + "-core"
}

Build -> Clean Project

查看更多
可以哭但决不认输i
4楼-- · 2019-02-05 17:27

File->Project structure->Project Settings->Modules->Language level

Change level using drop down.

Otherwise, If you are using maven for build,

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
</build>
查看更多
Ridiculous、
5楼-- · 2019-02-05 17:32

And, if you're working with a maven project, for sanity, remember to set the java version in the pom too.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
查看更多
别忘想泡老子
6楼-- · 2019-02-05 17:41

Ctrl+Alt+Shift+S (Project Structure icon)

Then change Project language level

查看更多
我命由我不由天
7楼-- · 2019-02-05 17:42

File -> Project Structure -> Sources -> Language level

You will have to reload IDEA

查看更多
登录 后发表回答