I have the following Java class:
import java.util.concurrent;
public class Test{
public static void main(String[] args){
ExecutorService ex = Executors.newCachedThreadPool();
for(int i=0; i<10; i++){
ex.execute(new PeerThread(i+1));
}
}
}
For some reason, .concurrent does not import correctly. Instead, it gives me the error:
import java.util.concurrent;
^
symbol: class concurrent
location: package java.util
Of course, it also gives me an error related to the usage of Executor, but that is to be expected if it can't find the concurrent package.
I downloaded the latest version of the SDK as well as the latest version of regular Java (as I was unsure whether or not this mattered).
java -version reports java 1.7.0_51.
http://www.java.com/en/download/installed.jsp reports Java 7 51 as well.
If it matters, I am running Mac OSX 10.9.1.
I'm sure it is something stupid.
Thanks in advance.
You just forgot the star to import all classes in the package java.util.concurrent
.
import java.util.concurrent.*;
Otherwise it thinks concurrent
is a class to be imported from java.util
, and of course it does not exist.
java.util.concurrent
is a package not Class.So use Specific class name to import from this package or else use *.
For example
use import java.util.concurrent.AbstractExecutorService;
or
import java.util.concurrent.*;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.