Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 cannot import java.util.function

Tags:

java

java-8

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).

like image 583
Ronit Avatar asked Aug 05 '14 03:08

Ronit


3 Answers

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.

like image 183
Elliott Frisch Avatar answered Oct 29 '22 09:10

Elliott Frisch


try

import java.util.function.Function;

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

like image 26
Tapan Pandya Avatar answered Oct 29 '22 11:10

Tapan Pandya


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.*;
like image 27
SpringLearner Avatar answered Oct 29 '22 09:10

SpringLearner