Optimight
Optimight

Reputation: 3061

References to interface static methods are allowed only at source level 1.8 or above

What do I need in order to solve this problem? How to change JRE Library in Eclipse Project?

import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Stream;
import java.util.stream.Collectors;

public class LabelGroup {
SortedSet<String> strSet1 = Stream.of("A", "B", "C", "D")
             .collect(Collectors.toUnmodifiableSet());
    
}

Eclipse shows at Stream.of:

References to interface static methods are allowed only at source level 1.8 or above

Tried to install new software from official site as suggested by wiki.

Response:

Could not find (the software).

About Eclipse: Eclipse IDE for Enterprise Java Developers Version: 2018-12 (4.10.0) Build id: 20181214-0600

Project Settings: java build path: JRE System Library [JavaSE - 1.7]

Upvotes: 11

Views: 31115

Answers (4)

Vladi
Vladi

Reputation: 2000

1)Press on your project with right click and choose "Properties" enter image description here

2)choose java build Path from the left side

enter image description here

3)Press on "JRE System Library[JavaSe-1.5]" and press on Edit button

  1. in the open window we will choose the right JRE ( I use 11) and press finish

enter image description here

5)press Apply and Apply and Close

enter image description here

The issue suppose disappear

Upvotes: 8

Obalolu
Obalolu

Reputation: 21

If you are sure you have Java >= 1.8 installed and is in use in your workspace, try confirming that you do not have 'Project Specific Settings' enabled for that particular project.

Upvotes: 1

Natasha Kurian
Natasha Kurian

Reputation: 415

If you're working on a maven project and you're not able to change the JRE Library in Eclipse, then you can add the following dependency to the pom.xml

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

Upvotes: 24

Anton Sorokin
Anton Sorokin

Reputation: 544

You have JDK 7 installed instead of JDK 8. The Stream API appeared only in Java 8. You can download Java 8(JDK 8 or OpenJDK) from the official site and install it as a JDK in your project.


Click on the Add Library button. It brings your screen to point to the Java location.

Select Directory, button right besides JRE home and point to the installed folder location.

Upvotes: 5

Related Questions