0
public void delete10(){
T s = null;
try {
s=x.pop();
while(s.avg()<10)
s=x.pop();
}
我越來越The method avg() is undefined for the type T
。現在我明白avg()
沒有在T
類型實現,但它在我將用它代替T
把這個通用的類型來實現。我怎樣才能做到這一點?泛型和方法
public E pop() throws EmptyStackException {
if (empty()) {
throw new EmptyStackException();
}
E result = top.item;
top = top.next;
return result;
}
你可以粘貼[SSCCE(http://sscce.org/) –
能否請你發佈你的類應該聲明類定義(即公共類Foo ...) –
MichaelMilom