6

I am trying to import the package java.util.function but I keep getting the following error:

FP.java:2: error: cannot find symbol
import java.util.function;
                ^
  symbol:   class function
  location: package java.util

I have verified that I am using jdk 1.8.0_11 (using javac -version).

0

5 Answers 5

16

That isn't how you import a package, this

import java.util.function;

should be

import java.util.function.*;

To import the classes in the java.util.function package.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, that was really silly of me. Can't believe I wasted so much time on this. Thanks.
4

try

import java.util.function.Function;

Function is a class under java.util.function package.

Comments

2

for importing all classes in package you have to use *

like

import x.y.*;

for importing only one class you should use class name like

import x.y.z;

for your case as function is a package so you should use

import java.util.function.*;

Comments

1

In case you are using Intellij, Go to Files > Settings > Build,Execution, Deployment > Compiiler > Java Compiler. In this, change the Target Bytecode version to 1.8.

Comments

1

I was also facing same issue while executing my project. As I had Java 15 on my machine , I changed targeted Bytecode version to 15 and it worked. Go to Files > Settings > Build,Execution, Deployment > Compiiler > Java Compiler. In this, change the Target Bytecode version to 15

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.