0
我有這個類,如下所示: -類型參數原因錯誤
import java.util.*;
public class QueueTest<T>{
Queue<T> q = new LinkedList<T>();
int capacity;
public QueueTest(int capacity){
this.capacity = capacity;
}
**public <T> void put(T item) throws InterruptedException**{
while(q.size()== capacity){
System.out.println("Now Queue is full and i will wait");
wait();
}
q.add(item);
System.out.println("I added : "+item);
notify();
}
public T got() throws InterruptedException{
while(q.isEmpty()){
System.out.println("Now Queue is empty and i will wait ");
wait();
}
T item = q.remove();
System.out.println("I got : "+item);
notify();
return item;
}
}
方法放的)聲明(導致此誤差Δθ
QueueTest.java:17: error: no suitable method found for add(T#1)
q.add(item);
,當我刪除牛逼,沒有錯誤編譯的類,但我不知道爲什麼???
謝謝,我明白了。 – Scorpion