为什么我不能构造一个由DelayQueue支持的ThreadPoolExecutor?

Avi*_*lax 3 java compiler-errors executors

我正在尝试创建一个ThreadPoolExecutor:

// Thingy implements Delayed and Runnable
ExecutorService executor = new ThreadPoolExecutor(1, 1, 0l, TimeUnit.SECONDS, new DelayQueue<Thingy>());
Run Code Online (Sandbox Code Playgroud)

编译器说"找不到符号":

symbol  : constructor ThreadPoolExecutor(int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.DelayQueue<Thingy>)
Run Code Online (Sandbox Code Playgroud)

但我不明白 - DelayQueue实现BlockingQueue,所以我不能使用这个构造函数

Dan*_*yer 7

这是一个泛型问题.你不能使用DelayQueue<Thingy>,它必须是DelayQueue<Runnable>因为ThreadPoolExecutor构造函数没有声明接受子类型的队列Runnable.