How to use Java 13 features in Eclipse?

1.7k views Asked by At

Is there a way to get Eclipse to understand Java 13 features, such as text blocks? Eclipse reports errors for the following code:

class Main {
    private String text = """
            first line
            second line
            third line
            """;
}

Errors include:

first cannot be resolved to a type
Duplicate field Main.line

I suspect the problem is the combination of Eclipse and Java 13 in general.

Building with Maven succeeds (with appropriate --enable-preview config). The "installed JRE" in use is Java 13 (with --enable-preview as default VM argument). Installing Java 13 Support for Eclipse 2019-09 doesn't seem to help either (doesn't add the Java 13 compliance level option).

2

There are 2 answers

7
www.hybriscx.com On

You would need to set JRE13 to eclipse and also will need to select BETA 13 under settings.

Check configuration steps at https://wiki.eclipse.org/Java13/Examples

In Project > Properies: Java Compiler make sure Java 13 preview features are enabled:

enter image description here

I did follow the steps and it worked for me.

Screenshots from MacOS

enter image description here

enter image description here

2
cowang On

Perhaps because I am using Cucumber for Eclipse, in addition to the steps given by @www.hybriscx.com, I had to make jdk-13 my selected JRE.

Image of Preferences -> Java -> Installed JREs page

Then I had to Edit that JDK-13 Installation to include the --enable-preview argument.

Image of Edit JRE page

I also set the Execution Environments page to set JavaSE-13 to use the jdk-13 JRE.

Image of Preferences -> Java -> Installed JREs -> Execution Environments