我SuperQueue类Instanize Java的泛型类其构造函数采用类对象参数
public class SuperQueue<E> implements Queue<E>{
SuperQueue(Class<? extends Queue<E>> subqClass) {}
}
如何创建一个SuperQueue对象?我曾尝试:
SuperQueue<Integer> superq = new SuperQueue<Integer> (ConcurrentLinkedQueue.class)
和
SuperQueue<Integer> superq = new SuperQueue<Integer> (ConcurrentLinkedQueue<Integer>.class)
你必须使用扩展队列的类。而不是类参考。有些东西像SuperQueue superq = new SuperQueue (new ConcurrentLinkedQueue ()) –
StackFlowed
2014-10-06 20:00:04
不是'new ConcurrentLinkedQueue()'创建队列对象而不是类对象吗? –
Tim
2014-10-06 20:02:57
是该行的含义是传递的对象应扩展类队列。 – StackFlowed 2014-10-06 20:04:14