Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The "import java.util.function cannot be resolved" error

I'm trying to run this practice script from the standard Oracle Java tutorials.

This seems to be a common error and I've used SO resources to make attempts to fix this. I've tried Cleaning the project, refreshing the project, switch workplace and switch back, removed and re-added the JRE7.

I don't know what else to do.

import java.util.List;
import java.util.function.Consumer; -----> cannot be resolved ERROR
import java.util.function.Function; -----> cannot be resolved ERROR
import java.util.Comparator;
import java.util.function.Predicate; -----> cannot be resolved ERROR
import java.lang.Iterable;
import java.time.chrono.IsoChronology; -----> cannot be resolved ERROR

public class LambdaExpressions_RosterTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

    }
like image 257
StacyM Avatar asked Aug 05 '14 01:08

StacyM


4 Answers

Per the java.util.function Javadoc,

Since:
      1.8

So upgrade to Java 8, or try to find an older version of the tutorial.

I'm new at this. How can you tell what you are running? I'm using Eclipse

To determine your current Java version in eclipse, go to

Help -> About Eclipse -> Installation Details (Button in
          lower Left) -> Configuration pane

Look for the line java.specification.version - on my machine that is

java.specification.version=1.8

Or the line java.runtime.version - on my machine that is

java.runtime.version=1.8.0_11-b12
like image 98
Elliott Frisch Avatar answered Oct 15 '22 06:10

Elliott Frisch


i solved this problem by trying following solution

Project > Properties > Java Build Path
Select Libraries tab
Select JRE System Library
Click Edit button
Choose an alternate JRE (jre1.8.0_20)
Click Finish button

like image 44
SoftwareDev Avatar answered Oct 15 '22 05:10

SoftwareDev


Lambda Expressions are newly added into Java 8. They are not available for JRE7. Try to upgrade your eclipse project's JRE to 8 (window -> preferences->java->compiler).

like image 4
Tapan Pandya Avatar answered Oct 15 '22 06:10

Tapan Pandya


For idea IntelliJ you need to go to Menu-> Project Structure -> Module here you will see Source tab, above this tab you can see language level. change it to more than 8.

-yash

like image 1
Yash Jagdale Avatar answered Oct 15 '22 07:10

Yash Jagdale