-1

I'm trying to update Java to Version 11, but don't want to use Oracles JDK because of the license. I also would like to install and use AdoptOpenJDK 8 because of that. My OS is Windows 10.

I've already tried to install AdoptOpenJDK 11 without overwriting any settings, as I want other java-programs to still run using Oracles JRE 8. I added the AdoptOpenJDK installation folder to the installed JREs in eclipse and when I ran some test code, "java.version" was set to 11.0.7, but when trying the new 'var' feature, Eclipse said that 'var' is not allowed here. I changed the compiler compliance level to 11 and updated to Eclipse Version 2020-03 (4.15.0), but it still didn't work.
Then I reinstalled AdoptOpenJDK 11 and let the installer change all the settings, but it still wouldn't work.

How can I install AdoptOpenJDK 8 and 11 parallel to OracleJDK 8 on my system and set in Eclipse which one to use per project?

EDIT: Ok, it works now, apparently I just didn't understand how to use 'var' correctly. Thank you for your help nonetheless.

Richard
  • 1
  • 2
  • 1
    Did you set the compiler compliance level via the _Properties_ item in the _Project_ menu, or via the _Preferences_ item in the _Window_ menu? You need to do it via the _Project > Properties_. – Abra May 01 '20 at 23:25
  • All JDKs/JREs must be configured in _Window > Preferences: Java > Installed JREs_ to be able to use them in projects and in launch configurations. – howlger May 02 '20 at 08:20
  • First I set the compiler compliance level in the _Window_ menu, but I tried it again in the _Project > Properties_ and it still wouldn't work. The JDK is configured in _Window > Preferences > Java > Installed JREs_. I added it by clicking _Add > Standard VM > Next_ and set the jre home to the AdoptOpenJDK installation path (`AdoptOpenJDK\jdk-11.0.7.10-hotspot`). – Richard May 02 '20 at 13:14

1 Answers1

0

The error message 'var' is not allowed here means that you are using Java 10 or higher, but var is used somewhere in the code where you cannot. Otherwise, for a compiler compliance level lower than 10, you would get var cannot be resolved to a type.

Example:

class Sample {

    var s = ""; // 'var' is not allowed here

    var foo() { // 'var' is not allowed here
        // ...
    }

    void foo(var x) { // 'var' is not allowed here
        // ...

        var s = ""; // okay

    }

}
howlger
  • 31,050
  • 11
  • 59
  • 99