I am using Eclipse (Mars.1 Release (4.5.1)) and encountering the following error: The method putIfAbsent(String, new PriorityQueue<>()) is undefined for the type
Map<String,PriorityQueue<String>>
. Everything seems done correctly but still getting the error. What could I be missing?
Map<String, PriorityQueue<String>> targets = new HashMap<>();
...
for(String[] ticket: tickets) {
targets.putIfAbsent(ticket[0], new PriorityQueue<>());
}
EDIT Did the following, yet still getting the error
EDIT 2
Added Java 8 SE, yet still getting the error.
EDIT 3
There's no method Map#putIfAbsent(K key, V value)
in Java 7, but there's in Java 8. See:
In your specific case, make sure the project properties under Eclipse (described below) are set to Java 8. You can edit them by doing: Right click on project > Properties:
Here's a possible solution:
If your Java Build Path is targeted to Java 7, follow the below steps to change it:
After setting this, you can continue to check the Java Complier.
Now, you should run your project without problem.
Do I have to do this to each project individually or does it apply to all projects?
You don't have to do this for each project. You can have a set-up for all projects of this workspace.
To setup Java Runtime Environments for all the projects, you can check which JREs are installed and change the default one.
JRE
As the screenshot shown: By default, the checked JRE is added to the build path of newly created Java projects. Now it should be OK for all the projects.
To edit the JRE for a specific project, you can. Here're the steps to do it: