Search code examples
javagradlelibgdxjava-8build.gradle

Using Java 8 with LibGDX


I'm writing a game in Java using LibGDX, with only desktop as the targeted platform. I just created a new LibGDX project, and imported some existing code into it, but now I'm getting a few errors. Specifically, using the diamond operator. For example, this line of code:

HashMap<String, Integer> connectionsMap = new HashMap<>();

is generating this error:

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

Ideally, I'd like to use Java 8. The Gradle files in the module I imported were preserved, so I changed the sourceCompatibility line in all the other build.gradle files throughout the project from 1.6 to 1.8, and I made sure that in the Project Structure > Project > Language Level was set to Java 8. However, I'm still getting this issue. What else do I need to change for my project to use Java 8?


Solution

  • If you're using IntelliJIDEA, make changes in three places.

    1. sourceCompatibility = 1.8 in build.gradle file of all modules

    2. Project Structure > Project > Language Level

    3. Project Structure > Modules > Sources Tab on all modules > Language Level